Minor fixes
- Added minor change to support all languages (Java 5.0+)
This commit is contained in:
parent
c8a541912f
commit
f83d25b732
15
.idea/misc.xml
generated
15
.idea/misc.xml
generated
@ -1,19 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="EntryPointsManager">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<entry_points version="2.0" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
|
||||||
<OptionsSetting value="true" id="Add" />
|
|
||||||
<OptionsSetting value="true" id="Remove" />
|
|
||||||
<OptionsSetting value="true" id="Checkout" />
|
|
||||||
<OptionsSetting value="true" id="Update" />
|
|
||||||
<OptionsSetting value="true" id="Status" />
|
|
||||||
<OptionsSetting value="true" id="Edit" />
|
|
||||||
<ConfirmationsSetting value="0" id="Add" />
|
|
||||||
<ConfirmationsSetting value="0" id="Remove" />
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_5" default="false" assert-keyword="true" jdk-15="true" project-jdk-name="9-ea" project-jdk-type="JavaSDK">
|
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -11,7 +11,7 @@ import java.util.Iterator;
|
|||||||
/**
|
/**
|
||||||
* Safe tools to help simplify code when dealing with reflection.
|
* Safe tools to help simplify code when dealing with reflection.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("ALL")
|
||||||
public class SafeReflection {
|
public class SafeReflection {
|
||||||
|
|
||||||
|
|
||||||
@ -25,18 +25,25 @@ public class SafeReflection {
|
|||||||
Method m = null, m1 = null, m2 = null, m3 = null;
|
Method m = null, m1 = null, m2 = null, m3 = null;
|
||||||
Field f = null;
|
Field f = null;
|
||||||
long l = 0;
|
long l = 0;
|
||||||
|
String version = "sun.reflect";
|
||||||
|
//Get package based on java version (Java 9+ use "jdk.internal.reflect" while "sun.reflect" is used by earlier versions)
|
||||||
|
try{
|
||||||
|
Class.forName("sun.reflect.DelegatingConstructorAccessorImpl");
|
||||||
|
}catch(Throwable ignored){
|
||||||
|
version="jdk.internal.reflect";
|
||||||
|
}
|
||||||
try{
|
try{
|
||||||
Class<?> c;
|
Class<?> c;
|
||||||
f = Unsafe.class.getDeclaredField("theUnsafe");
|
f = Unsafe.class.getDeclaredField("theUnsafe");
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
u = (Unsafe) f.get(null);
|
u = (Unsafe) f.get(null);
|
||||||
m = Class.forName("jdk.internal.reflect.ConstructorAccessor").getDeclaredMethod("newInstance", Object[].class);
|
m = Class.forName(version+".DelegatingConstructorAccessorImpl").getDeclaredMethod("newInstance", Object[].class);
|
||||||
u.putBoolean(m, l=u.objectFieldOffset(AccessibleObject.class.getDeclaredField("override")), true);
|
u.putBoolean(m, l=u.objectFieldOffset(AccessibleObject.class.getDeclaredField("override")), true);
|
||||||
m1 = Constructor.class.getDeclaredMethod("acquireConstructorAccessor");
|
m1 = Constructor.class.getDeclaredMethod("acquireConstructorAccessor");
|
||||||
m1.setAccessible(true);
|
m1.setAccessible(true);
|
||||||
m2 = Field.class.getDeclaredMethod("getFieldAccessor", Object.class);
|
m2 = Field.class.getDeclaredMethod("getFieldAccessor", Object.class);
|
||||||
m2.setAccessible(true);
|
m2.setAccessible(true);
|
||||||
m3 = (c=Class.forName("jdk.internal.reflect.UnsafeQualifiedStaticObjectFieldAccessorImpl")).getDeclaredMethod("set", Object.class, Object.class);
|
m3 = (c=Class.forName(version+".UnsafeQualifiedStaticObjectFieldAccessorImpl")).getDeclaredMethod("set", Object.class, Object.class);
|
||||||
u.putBoolean(m3, l, true);
|
u.putBoolean(m3, l, true);
|
||||||
f = c.getSuperclass().getDeclaredField("isReadOnly");
|
f = c.getSuperclass().getDeclaredField("isReadOnly");
|
||||||
u.putBoolean(f, l, true);
|
u.putBoolean(f, l, true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user