mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-24 18:18:05 +01:00
Improve reliability of java version check in ReflectionClassLoader (#2093)
This commit is contained in:
parent
30d7768299
commit
2adea2d3dc
@ -52,7 +52,7 @@ public class ReflectionClassLoader implements PluginClassLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.addUrlMethod = Suppliers.memoize(() -> {
|
this.addUrlMethod = Suppliers.memoize(() -> {
|
||||||
if (getJavaMajorVersion() >= 9) {
|
if (isJava9OrNewer()) {
|
||||||
bootstrap.getPluginLogger().info("It is safe to ignore any warning printed following this message " +
|
bootstrap.getPluginLogger().info("It is safe to ignore any warning printed following this message " +
|
||||||
"starting with 'WARNING: An illegal reflective access operation has occurred, Illegal reflective " +
|
"starting with 'WARNING: An illegal reflective access operation has occurred, Illegal reflective " +
|
||||||
"access by " + getClass().getName() + "'.");
|
"access by " + getClass().getName() + "'.");
|
||||||
@ -78,16 +78,13 @@ public class ReflectionClassLoader implements PluginClassLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getJavaMajorVersion() {
|
private static boolean isJava9OrNewer() {
|
||||||
String version = System.getProperty("java.version");
|
try {
|
||||||
if (version.startsWith("1.")) {
|
// method was added in the Java 9 release
|
||||||
version = version.substring(2, 3);
|
Runtime.class.getMethod("version");
|
||||||
} else {
|
return true;
|
||||||
int dot = version.indexOf(".");
|
} catch (NoSuchMethodException e) {
|
||||||
if (dot != -1) {
|
return false;
|
||||||
version = version.substring(0, dot);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Integer.parseInt(version);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user