Changed TypeResolver to use OS.javaVersion instead of using it's own.

This commit is contained in:
nathan 2018-08-07 23:32:52 +02:00
parent 261f6b869d
commit 134678c369

View File

@ -36,6 +36,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import dorkbox.util.OS;
import sun.misc.Unsafe; import sun.misc.Unsafe;
/** /**
@ -62,11 +63,7 @@ class TypeResolver {
private static final Map<String, Method> OBJECT_METHODS = new HashMap<String, Method>(); private static final Map<String, Method> OBJECT_METHODS = new HashMap<String, Method>();
private static final Map<Class<?>, Class<?>> PRIMITIVE_WRAPPERS; private static final Map<Class<?>, Class<?>> PRIMITIVE_WRAPPERS;
private static final Double JAVA_VERSION;
static { static {
JAVA_VERSION = Double.parseDouble(System.getProperty("java.specification.version", "0"));
try { try {
Unsafe unsafe = AccessController.doPrivileged(new PrivilegedExceptionAction<Unsafe>() { Unsafe unsafe = AccessController.doPrivileged(new PrivilegedExceptionAction<Unsafe>() {
@Override @Override
@ -80,7 +77,7 @@ class TypeResolver {
}); });
GET_CONSTANT_POOL = Class.class.getDeclaredMethod("getConstantPool"); GET_CONSTANT_POOL = Class.class.getDeclaredMethod("getConstantPool");
String constantPoolName = JAVA_VERSION < 9 ? "sun.reflect.ConstantPool" : "jdk.internal.reflect.ConstantPool"; String constantPoolName = OS.javaVersion < 9 ? "sun.reflect.ConstantPool" : "jdk.internal.reflect.ConstantPool";
Class<?> constantPoolClass = Class.forName(constantPoolName); Class<?> constantPoolClass = Class.forName(constantPoolName);
GET_CONSTANT_POOL_SIZE = constantPoolClass.getDeclaredMethod("getSize"); GET_CONSTANT_POOL_SIZE = constantPoolClass.getDeclaredMethod("getSize");
GET_CONSTANT_POOL_METHOD_AT = constantPoolClass.getDeclaredMethod("getMethodAt", int.class); GET_CONSTANT_POOL_METHOD_AT = constantPoolClass.getDeclaredMethod("getMethodAt", int.class);
@ -543,7 +540,7 @@ class TypeResolver {
private static private static
boolean isDefaultMethod(Method m) { boolean isDefaultMethod(Method m) {
return JAVA_VERSION >= 1.8 && DefaultMethodHelper.isDefaultMethod(m); return OS.javaVersion >= 8 && DefaultMethodHelper.isDefaultMethod(m);
} }
private static private static