mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-05 02:58:20 +08:00
放弃Unsafe包操作
This commit is contained in:
@@ -59,4 +59,6 @@ public class FieldOffset implements Comparable<FieldOffset> {
|
||||
public int compareTo(@NotNull FieldOffset that) {
|
||||
return this.offsetValue.compareTo(that.offsetValue);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package config.offset;
|
||||
|
||||
import jdk.internal.misc.Unsafe;
|
||||
|
||||
import sun.misc.Unsafe;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -18,14 +17,23 @@ public class OffsetUtil {
|
||||
|
||||
static {
|
||||
try {
|
||||
unsafe = AccessController.doPrivileged((PrivilegedExceptionAction<Unsafe>) () -> {
|
||||
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
theUnsafe.setAccessible(true);
|
||||
return (Unsafe) theUnsafe.get(null);
|
||||
});
|
||||
} catch (Throwable e) {
|
||||
System.err.println("Unable to load unsafe");
|
||||
// 获取 Unsafe 内部的私有的实例化单例对象
|
||||
Field field = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
// 无视权限
|
||||
field.setAccessible(true);
|
||||
unsafe = (Unsafe) field.get(null);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// try {
|
||||
// unsafe = AccessController.doPrivileged((PrivilegedExceptionAction<Unsafe>) () -> {
|
||||
// Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
|
||||
// theUnsafe.setAccessible(true);
|
||||
// return (Unsafe) theUnsafe.get(null);
|
||||
// });
|
||||
// } catch (Throwable e) {
|
||||
// System.err.println("Unable to load unsafe");
|
||||
// }
|
||||
}
|
||||
|
||||
public static List<FieldOffset> getClassMemberOffset(Class<?> beanClass) {
|
||||
|
||||
Reference in New Issue
Block a user