aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiam Miller-Cushon <cushon@google.com>2021-12-23 11:50:04 -0800
committerJavac Team <javac-team+copybara@google.com>2021-12-23 11:50:45 -0800
commitf9e53658f7493651756722f1088f8d489ba83eed (patch)
tree8b17a49a7efa35a239363d45e3471ea6cf4c4b4c
parent1a1f08ee637558d6255a4957886d8ea67db5c34b (diff)
downloadturbine-f9e53658f7493651756722f1088f8d489ba83eed.tar.gz
Remove uses of reflection now that we're testing on JDK 11+
PiperOrigin-RevId: 418042741
-rw-r--r--java/com/google/turbine/binder/CtSymClassBinder.java18
1 files changed, 3 insertions, 15 deletions
diff --git a/java/com/google/turbine/binder/CtSymClassBinder.java b/java/com/google/turbine/binder/CtSymClassBinder.java
index 3bf04c8..f0e21f2 100644
--- a/java/com/google/turbine/binder/CtSymClassBinder.java
+++ b/java/com/google/turbine/binder/CtSymClassBinder.java
@@ -35,7 +35,6 @@ import com.google.turbine.binder.sym.ClassSymbol;
import com.google.turbine.binder.sym.ModuleSymbol;
import com.google.turbine.zip.Zip;
import java.io.IOException;
-import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -46,6 +45,8 @@ import org.jspecify.nullness.Nullable;
/** Constructs a platform {@link ClassPath} from the current JDK's ct.sym file. */
public final class CtSymClassBinder {
+ private static final int FEATURE_VERSION = Runtime.version().feature();
+
public static @Nullable ClassPath bind(int version) throws IOException {
String javaHome = JAVA_HOME.value();
requireNonNull(javaHome, "attempted to use --release, but JAVA_HOME is not set");
@@ -79,7 +80,7 @@ public final class CtSymClassBinder {
if (!ze.name().substring(0, idx).contains(releaseString)) {
continue;
}
- if (isAtLeastJDK12()) {
+ if (FEATURE_VERSION >= 12) {
// JDK >= 12 includes the module name as a prefix
idx = name.indexOf('/', idx + 1);
}
@@ -140,18 +141,5 @@ public final class CtSymClassBinder {
return toUpperCase(Integer.toString(n, 36));
}
- private static boolean isAtLeastJDK12() {
- int major;
- try {
- Method versionMethod = Runtime.class.getMethod("version");
- Object version = versionMethod.invoke(null);
- major = (int) version.getClass().getMethod("major").invoke(version);
- } catch (ReflectiveOperationException e) {
- // `Runtime.version()` was added in JDK 9
- return false;
- }
- return major >= 12;
- }
-
private CtSymClassBinder() {}
}