Skip to content

Commit 6aa2304

Browse files
committed
Improve support for Java 15, OpenHFT/Chronicle-Core#210
1 parent 875854b commit 6aa2304

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/main/java/net/openhft/compiler/MyJavaFileManager.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525

2626
import javax.tools.*;
2727
import javax.tools.JavaFileObject.Kind;
28-
import java.io.*;
28+
import java.io.ByteArrayInputStream;
29+
import java.io.IOException;
30+
import java.io.InputStream;
31+
import java.io.OutputStream;
2932
import java.lang.reflect.AccessibleObject;
3033
import java.lang.reflect.Field;
3134
import java.lang.reflect.InvocationTargetException;
@@ -42,15 +45,21 @@ class MyJavaFileManager implements JavaFileManager {
4245
private static final long OVERRIDE_OFFSET;
4346

4447
static {
48+
long offset = 0;
4549
try {
4650
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
4751
theUnsafe.setAccessible(true);
4852
unsafe = (Unsafe) theUnsafe.get(null);
49-
Field f = AccessibleObject.class.getDeclaredField("override");
50-
OVERRIDE_OFFSET = unsafe.objectFieldOffset(f);
5153
} catch (Exception ex) {
5254
throw new AssertionError(ex);
5355
}
56+
try {
57+
Field f = AccessibleObject.class.getDeclaredField("override");
58+
offset = unsafe.objectFieldOffset(f);
59+
} catch (NoSuchFieldException e) {
60+
offset = 0;
61+
}
62+
OVERRIDE_OFFSET = offset;
5463
}
5564

5665
private final StandardJavaFileManager fileManager;
@@ -197,7 +206,10 @@ private <T> T invokeNamedMethodIfAvailable(final Location location, final String
197206
if (method.getName().equals(name) && method.getParameterTypes().length == 1 &&
198207
method.getParameterTypes()[0] == Location.class) {
199208
try {
200-
unsafe.putBoolean(method, OVERRIDE_OFFSET, true);
209+
if (OVERRIDE_OFFSET == 0)
210+
method.setAccessible(true);
211+
else
212+
unsafe.putBoolean(method, OVERRIDE_OFFSET, true);
201213
return (T) method.invoke(fileManager, location);
202214
} catch (IllegalAccessException | InvocationTargetException e) {
203215
throw new UnsupportedOperationException("Unable to invoke method " + name);

0 commit comments

Comments
 (0)