11package com .sourcegraph .scip_semanticdb ;
22
3- import java .io .DataInputStream ;
43import java .io .IOException ;
54import java .io .InputStream ;
65import java .nio .file .FileSystems ;
1110import java .util .Optional ;
1211import java .util .jar .JarEntry ;
1312import java .util .jar .JarFile ;
13+ import java .io .DataInputStream ;
1414
1515public class JavaVersion {
1616 public final boolean isJava8 ;
1717 public final JdkPackage pkg ;
18- private static final PathMatcher CLASS_PATTERN =
19- FileSystems .getDefault ().getPathMatcher ("glob:**.class" );
20- private static final PathMatcher JAR_PATTERN =
21- FileSystems .getDefault ().getPathMatcher ("glob:**.jar" );
18+ private static final PathMatcher CLASS_PATTERN = FileSystems .getDefault ().getPathMatcher ("glob:**.class" );
19+ private static final PathMatcher JAR_PATTERN = FileSystems .getDefault ().getPathMatcher ("glob:**.jar" );
2220
2321 public static final int JAVA8_VERSION = 8 ;
2422 public static final int JAVA11_VERSION = 11 ;
2523 public static final int JAVA17_VERSION = 17 ;
24+ public static final int JAVA21_VERSION = 21 ;
25+ public static final int JAVA25_VERSION = 25 ;
2626 public static final int DEFAULT_JAVA_VERSION = JAVA8_VERSION ;
2727
2828 @ SuppressWarnings ("FieldCanBeLocal" )
@@ -38,28 +38,41 @@ public JavaVersion(String version) {
3838 }
3939
4040 private String javaVersion (String version ) {
41- if (version .startsWith ("1.8" )) return "8" ;
41+ if (version .startsWith ("1.8" ))
42+ return "8" ;
4243 String [] parts = version .split ("\\ ." );
43- if (parts .length > 0 ) return parts [0 ];
44- else return version ;
44+ if (parts .length > 0 )
45+ return parts [0 ];
46+ else
47+ return version ;
4548 }
4649
4750 @ SuppressWarnings ("ManualMinMaxCalculation" )
4851 public static int roundToNearestStableRelease (int version ) {
49- if (version <= JAVA8_VERSION ) return JAVA8_VERSION ;
50- if (version <= JAVA11_VERSION ) return JAVA11_VERSION ;
51- if (version <= JAVA17_VERSION ) return JAVA17_VERSION ;
52+ if (version <= JAVA8_VERSION )
53+ return JAVA8_VERSION ;
54+ if (version <= JAVA11_VERSION )
55+ return JAVA11_VERSION ;
56+ if (version <= JAVA17_VERSION )
57+ return JAVA17_VERSION ;
58+ if (version <= JAVA21_VERSION )
59+ return JAVA21_VERSION ;
60+ if (version <= JAVA25_VERSION )
61+ return JAVA25_VERSION ;
5262 return version ;
5363 }
5464
5565 /**
5666 * Return the JVM version of the given jar/class file.
5767 *
58- * <p>The JVM version is determined by reading the 5-8th bytes of classfiles, according to the
68+ * <p>
69+ * The JVM version is determined by reading the 5-8th bytes of classfiles,
70+ * according to the
5971 * Java Language spec. See
6072 * https://docs.oracle.com/javase/specs/jvms/se16/html/jvms-4.html#jvms-4.1
6173 *
62- * @return the JVM version such as <code>8</code> for Java 8 and <code>11</code> for Java 11.
74+ * @return the JVM version such as <code>8</code> for Java 8 and <code>11</code>
75+ * for Java 11.
6376 */
6477 public static Optional <Integer > classfileJvmVersion (Path file ) {
6578 try {
@@ -92,7 +105,8 @@ private static int classfileMajorVersion(InputStream classfileBytes) throws IOEx
92105 DataInputStream in = new DataInputStream (classfileBytes );
93106 // See https://docs.oracle.com/javase/specs/jvms/se16/html/jvms-4.html#jvms-4.1
94107 int magic = in .readInt (); // u4 magic
95- if (magic != 0xCAFEBABE ) return -1 ;
108+ if (magic != 0xCAFEBABE )
109+ return -1 ;
96110 in .readUnsignedShort (); // u2 minor_version
97111 return in .readUnsignedShort (); // u2 major_version
98112 }
0 commit comments