mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 14:17:48 +00:00
[fixes #2085] JDK12 compatibility. Also acknowledging @nqzero for the permit-reflect library which is inspiring our shenanigans :)
This commit is contained in:
2 files changed
+27
-2
No files matched your search
@@ -46,8 +46,7 @@ public class Permit {
|
||||
Throwable ex;
|
||||
|
||||
try {
|
||||
f = AccessibleObject.class.getDeclaredField("override");
|
||||
g = UNSAFE.objectFieldOffset(f);
|
||||
g = getOverrideFieldOffset();
|
||||
ex = null;
|
||||
} catch (Throwable t) {
|
||||
f = null;
|
||||
@@ -74,6 +73,30 @@ public class Permit {
|
||||
return accessor;
|
||||
}
|
||||
|
||||
private static long getOverrideFieldOffset() throws Throwable {
|
||||
Field f = null;
|
||||
Throwable saved = null;
|
||||
try {
|
||||
f = AccessibleObject.class.getDeclaredField("override");
|
||||
} catch (Throwable t) {
|
||||
saved = t;
|
||||
}
|
||||
|
||||
if (f != null) {
|
||||
return UNSAFE.objectFieldOffset(f);
|
||||
}
|
||||
// The below seems very risky, but for all AccessibleObjects in java today it does work, and starting with JDK12, making the field accessible is no longer possible.
|
||||
try {
|
||||
return UNSAFE.objectFieldOffset(Fake.class.getDeclaredField("override"));
|
||||
} catch (Throwable t) {
|
||||
throw saved;
|
||||
}
|
||||
}
|
||||
|
||||
static class Fake {
|
||||
boolean override;
|
||||
}
|
||||
|
||||
public static Method getMethod(Class<?> c, String mName, Class<?>... parameterTypes) throws NoSuchMethodException {
|
||||
Method m = null;
|
||||
Class<?> oc = c;
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
<strong>Perry Nguyen</strong> (pfn on ##java on freenode) for creating the inspiration for project lombok.
|
||||
</li><li>
|
||||
<strong>Tor Norbye</strong>, <strong>Jan Lahoda</strong>, and <strong>Petr Jiricka</strong> for helping out with Netbeans internals and/or javac.
|
||||
</li><li>
|
||||
<strong>nqzero</strong> for the <a href="https://github.com/nqzero/permit-reflect">permit-reflect</a> library, whose ideas are also used in lombok.
|
||||
</li><li>
|
||||
All contributors who submitted patches or helped answering questions!</li>
|
||||
</ul>
|
||||
|
||||
Reference in new issue
Block a user