diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-02-06 05:43:10 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2018-02-06 06:20:44 +0100 |
commit | e9d86650ffae683d86e59cff96c74a7c9931b6d0 (patch) | |
tree | 5f59088546cb098737fe8e9af4dac23c2980853d /src/launch/lombok | |
parent | fee0ad33abceb0219076dde05c9d5d9ba950000f (diff) | |
download | lombok-e9d86650ffae683d86e59cff96c74a7c9931b6d0.tar.gz lombok-e9d86650ffae683d86e59cff96c74a7c9931b6d0.tar.bz2 lombok-e9d86650ffae683d86e59cff96c74a7c9931b6d0.zip |
[jdk9] [opinionated] The java9 warning when using lombok about ‘inaccessible API’ is now suppressed.
Diffstat (limited to 'src/launch/lombok')
-rw-r--r-- | src/launch/lombok/launch/AnnotationProcessor.java | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/launch/lombok/launch/AnnotationProcessor.java b/src/launch/lombok/launch/AnnotationProcessor.java index 05c900ab..b92cad91 100644 --- a/src/launch/lombok/launch/AnnotationProcessor.java +++ b/src/launch/lombok/launch/AnnotationProcessor.java @@ -21,6 +21,7 @@ */ package lombok.launch; +import java.lang.reflect.Field; import java.util.Set; import javax.annotation.processing.AbstractProcessor; @@ -37,6 +38,8 @@ import javax.lang.model.type.TypeMirror; import org.mapstruct.ap.spi.AstModifyingAnnotationProcessor; +import sun.misc.Unsafe; + class AnnotationProcessorHider { public static class AstModificationNotifier implements AstModifyingAnnotationProcessor { @Override public boolean isTypeComplete(TypeMirror type) { @@ -65,11 +68,33 @@ class AnnotationProcessorHider { } @Override public void init(ProcessingEnvironment processingEnv) { + disableJava9SillyWarning(); AstModificationNotifierData.lombokInvoked = true; instance.init(processingEnv); super.init(processingEnv); } + // sunapi suppresses javac's warning about using Unsafe; 'all' suppresses eclipse's warning about the unspecified 'sunapi' key. Leave them both. + // Yes, javac's definition of the word 'all' is quite contrary to what the dictionary says it means. 'all' does NOT include 'sunapi' according to javac. + @SuppressWarnings({"sunapi", "all"}) + private void disableJava9SillyWarning() { + // JVM9 complains about using reflection to access packages from a module that aren't exported. This makes no sense; the whole point of reflection + // is to get past such issues. The only comment from the jigsaw team lead on this was some unspecified mumbling about security which makes no sense, + // as the SecurityManager is invoked to check such things. Therefore this warning is a bug, so we shall patch java to fix it. + + try { + Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe"); + theUnsafe.setAccessible(true); + Unsafe u = (Unsafe) theUnsafe.get(null); + + Class<?> cls = Class.forName("jdk.internal.module.IllegalAccessLogger"); + Field logger = cls.getDeclaredField("logger"); + u.putObjectVolatile(cls, u.staticFieldOffset(logger), null); + } catch (Throwable t) { + // We shall ignore it; the effect of this code failing is that the user gets to see a warning they remove with various --add-opens magic. + } + } + @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { return instance.process(annotations, roundEnv); } @@ -82,7 +107,7 @@ class AnnotationProcessorHider { ClassLoader cl = Main.createShadowClassLoader(); try { Class<?> mc = cl.loadClass("lombok.core.AnnotationProcessor"); - return (AbstractProcessor) mc.newInstance(); + return (AbstractProcessor) mc.getDeclaredConstructor().newInstance(); } catch (Throwable t) { if (t instanceof Error) throw (Error) t; if (t instanceof RuntimeException) throw (RuntimeException) t; |