Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a different method to determine if we are on Java 11 #1385

Merged
merged 1 commit into from
Sep 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/org/mozilla/javascript/JavaMembers.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.lang.model.SourceVersion;

/**
* @author Mike Shaver
Expand All @@ -33,8 +32,7 @@
*/
class JavaMembers {

private static final boolean STRICT_REFLECTIVE_ACCESS =
SourceVersion.latestSupported().ordinal() > 8;
private static final boolean STRICT_REFLECTIVE_ACCESS = isModularJava();

private static final Permission allPermission = new AllPermission();

Expand All @@ -59,6 +57,19 @@ class JavaMembers {
}
}

/**
* This method returns true if we are on a "modular" version of Java (Java 11 or up). It does
* not use the SourceVersion class because this is not present on Android.
*/
private static boolean isModularJava() {
try {
Class.class.getMethod("getModule");
return true;
} catch (NoSuchMethodException e) {
return false;
}
}

boolean has(String name, boolean isStatic) {
Map<String, Object> ht = isStatic ? staticMembers : members;
Object obj = ht.get(name);
Expand Down