aboutsummaryrefslogtreecommitdiff
path: root/src/launch
diff options
context:
space:
mode:
Diffstat (limited to 'src/launch')
-rw-r--r--src/launch/lombok/launch/AnnotationProcessor.java44
-rw-r--r--src/launch/lombok/launch/ShadowClassLoader.java19
2 files changed, 56 insertions, 7 deletions
diff --git a/src/launch/lombok/launch/AnnotationProcessor.java b/src/launch/lombok/launch/AnnotationProcessor.java
index 93fba196..c4f922b9 100644
--- a/src/launch/lombok/launch/AnnotationProcessor.java
+++ b/src/launch/lombok/launch/AnnotationProcessor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014-2016 The Project Lombok Authors.
+ * Copyright (C) 2014-2018 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -21,6 +21,7 @@
*/
package lombok.launch;
+import java.lang.reflect.Field;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
@@ -33,8 +34,24 @@ import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
+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) {
+ if (System.getProperty("lombok.disable") != null) return true;
+ return AstModificationNotifierData.lombokInvoked;
+ }
+ }
+
+ static class AstModificationNotifierData {
+ volatile static boolean lombokInvoked = false;
+ }
+
public static class AnnotationProcessor extends AbstractProcessor {
private final AbstractProcessor instance = createWrappedInstance();
@@ -51,10 +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);
}
@@ -67,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;
diff --git a/src/launch/lombok/launch/ShadowClassLoader.java b/src/launch/lombok/launch/ShadowClassLoader.java
index cd11720a..36dd289c 100644
--- a/src/launch/lombok/launch/ShadowClassLoader.java
+++ b/src/launch/lombok/launch/ShadowClassLoader.java
@@ -123,10 +123,14 @@ class ShadowClassLoader extends ClassLoader {
SELF_BASE = selfBase;
SELF_BASE_LENGTH = selfBase.length();
} else {
- String sclClassUrl = ShadowClassLoader.class.getResource("ShadowClassLoader.class").toString();
- if (!sclClassUrl.endsWith(SELF_NAME)) throw new InternalError("ShadowLoader can't find itself.");
- SELF_BASE_LENGTH = sclClassUrl.length() - SELF_NAME.length();
- String decoded = urlDecode(sclClassUrl.substring(0, SELF_BASE_LENGTH));
+ URL sclClassUrl = ShadowClassLoader.class.getResource("ShadowClassLoader.class");
+ String sclClassStr = sclClassUrl == null ? null : sclClassUrl.toString();
+ if (sclClassStr == null || !sclClassStr.endsWith(SELF_NAME)) {
+ ClassLoader cl = ShadowClassLoader.class.getClassLoader();
+ throw new RuntimeException("ShadowLoader can't find itself. SCL loader type: " + (cl == null ? "*NULL*" : cl.getClass().toString()));
+ }
+ SELF_BASE_LENGTH = sclClassStr.length() - SELF_NAME.length();
+ String decoded = urlDecode(sclClassStr.substring(0, SELF_BASE_LENGTH));
SELF_BASE = decoded;
}
@@ -558,7 +562,12 @@ class ShadowClassLoader extends ClassLoader {
Class<?> alreadyDefined = highlanderMap.get(name);
if (alreadyDefined != null) return alreadyDefined;
}
- throw e;
+ try {
+ c = this.findLoadedClass(name);
+ } catch (LinkageError e2) {
+ throw e;
+ }
+ if (c == null) throw e;
}
if (highlanders.contains(name)) {