Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<sourceDirectory>src</sourceDirectory>
</build>
<properties>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<name>permit-reflect</name>
<description>reflection utils for jigsaw</description>
Expand Down
29 changes: 3 additions & 26 deletions src/com/nqzero/permit/Permit.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// copyright 2018 nqzero - offered under the terms of the MIT License
// copyright 2021 nqzero - offered under the terms of the MIT License

package com.nqzero.permit;

Expand All @@ -13,36 +13,13 @@ public class Permit<TT,VV> extends Safer<TT,VV> {
public static final String splitChar = "\\.";

static Exception savedEx;
static Permit<AccessibleObject,Boolean> override;
static {
getOverride();
}

static void getOverride() {
Permit fake = null;
Exception saved = null;
try { override = build(AccessibleObject.class,"override"); }
catch (Exception ex) { saved = ex; }
if (saved != null)
try {
fake = build(Fake.class,"override");
fake.klass = AccessibleObject.class;
override = fake;
return;
}
catch (Exception ex) {}
savedEx = saved;
}

public static void setAccessible(AccessibleObject accessor) throws InitializationFailed {
if (savedEx != null)
throw new InitializationFailed();
override.putBoolean(accessor,true);
}
static class Fake {
boolean override;
accessor.setAccessible(true);
}

public static boolean initSucceeded(boolean rethrow) {
if (savedEx==null)
return true;
Expand Down
20 changes: 11 additions & 9 deletions src/com/nqzero/permit/Unsafer.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
// copyright 2018 nqzero - offered under the terms of the MIT License
// copyright 2021 nqzero - offered under the terms of the MIT License

package com.nqzero.permit;

import java.lang.reflect.Field;
import sun.misc.Unsafe;

public class Unsafer {
private static Object getField(Class klass,String name) {

public static final Unsafe uu;

static {
try {
Field f = klass.getDeclaredField(name);
f.setAccessible(true);
return f.get(null);
Field field = Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
uu = (Unsafe) field.get(null);
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new ExceptionInInitializerError(e);
}
catch (Exception e) { return null; }
}
public static final sun.misc.Unsafe uu =
(sun.misc.Unsafe) getField(sun.misc.Unsafe.class,"theUnsafe");

}