Skip to content

Commit

Permalink
Use a different method to determine if we are on Java 11
Browse files Browse the repository at this point in the history
This should be more likely to work on Android.
  • Loading branch information
gbrail committed Sep 9, 2023
1 parent 1485f1e commit d421fe3
Showing 1 changed file with 14 additions and 3 deletions.
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

0 comments on commit d421fe3

Please sign in to comment.