aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-05-06 21:26:29 +0200
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2019-05-06 21:26:29 +0200
commitd41e804fe73faed5f8b90f4b472728bc3a0c85b7 (patch)
treef47d82c4f383cfdb242c803c88eadde5c2982944 /src
parent2335f251665d43b4c8cebe00b980f07ef33bdb17 (diff)
downloadlombok-d41e804fe73faed5f8b90f4b472728bc3a0c85b7.tar.gz
lombok-d41e804fe73faed5f8b90f4b472728bc3a0c85b7.tar.bz2
lombok-d41e804fe73faed5f8b90f4b472728bc3a0c85b7.zip
[trivial] replacing all calls to Class.newInstance() with Class.getConstructor().newInstance to avoid warnings which are default in many JDK11+ environments, and it shouldn’t change anything (we handle the change from sneaky throwing to InvocationTargetException appropriately).
Diffstat (limited to 'src')
-rw-r--r--src/core/lombok/core/AgentLauncher.java4
-rw-r--r--src/core/lombok/core/AnnotationProcessor.java2
-rw-r--r--src/delombok/lombok/delombok/ant/DelombokTask.java4
-rw-r--r--src/utils/lombok/core/SpiLoadUtil.java10
-rw-r--r--src/utils/lombok/javac/Javac.java8
5 files changed, 19 insertions, 9 deletions
diff --git a/src/core/lombok/core/AgentLauncher.java b/src/core/lombok/core/AgentLauncher.java
index 1d5ab3e6..5b5af7ba 100644
--- a/src/core/lombok/core/AgentLauncher.java
+++ b/src/core/lombok/core/AgentLauncher.java
@@ -22,6 +22,7 @@
package lombok.core;
import java.lang.instrument.Instrumentation;
+import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -35,9 +36,10 @@ public class AgentLauncher {
for (AgentInfo info : AGENTS) {
try {
Class<?> agentClass = Class.forName(info.className());
- AgentLaunchable agent = (AgentLaunchable) agentClass.newInstance();
+ AgentLaunchable agent = (AgentLaunchable) agentClass.getConstructor().newInstance();
agent.runAgent(agentArgs, instrumentation, injected, launchingContext);
} catch (Throwable t) {
+ if (t instanceof InvocationTargetException) t = t.getCause();
info.problem(t, instrumentation);
}
}
diff --git a/src/core/lombok/core/AnnotationProcessor.java b/src/core/lombok/core/AnnotationProcessor.java
index 363952a4..46e3b1af 100644
--- a/src/core/lombok/core/AnnotationProcessor.java
+++ b/src/core/lombok/core/AnnotationProcessor.java
@@ -112,7 +112,7 @@ public class AnnotationProcessor extends AbstractProcessor {
try {
ClassLoader classLoader = findAndPatchClassLoader(javacProcEnv);
- processor = (Processor) Class.forName("lombok.javac.apt.LombokProcessor", false, classLoader).newInstance();
+ processor = (Processor) Class.forName("lombok.javac.apt.LombokProcessor", false, classLoader).getConstructor().newInstance();
} catch (Exception e) {
delayedWarnings.add("You found a bug in lombok; lombok.javac.apt.LombokProcessor is not available. Lombok will not run during this compilation: " + trace(e));
return false;
diff --git a/src/delombok/lombok/delombok/ant/DelombokTask.java b/src/delombok/lombok/delombok/ant/DelombokTask.java
index cb31ef4d..defd1709 100644
--- a/src/delombok/lombok/delombok/ant/DelombokTask.java
+++ b/src/delombok/lombok/delombok/ant/DelombokTask.java
@@ -188,7 +188,7 @@ class Tasks {
Location loc = getLocation();
try {
- Object instance = shadowLoadClass("lombok.delombok.ant.DelombokTaskImpl").newInstance();
+ Object instance = shadowLoadClass("lombok.delombok.ant.DelombokTaskImpl").getConstructor().newInstance();
for (Field selfField : getClass().getDeclaredFields()) {
if (selfField.isSynthetic() || Modifier.isStatic(selfField.getModifiers())) continue;
Field otherField = instance.getClass().getDeclaredField(selfField.getName());
@@ -208,7 +208,7 @@ class Tasks {
Method m = instance.getClass().getMethod("execute", Location.class);
m.invoke(instance, loc);
} catch (Exception e) {
- Throwable t = (e instanceof InvocationTargetException) ? ((InvocationTargetException) e).getCause() : e;
+ Throwable t = (e instanceof InvocationTargetException) ? e.getCause() : e;
if (t instanceof Error) throw (Error) t;
if (t instanceof RuntimeException) throw (RuntimeException) t;
throw new RuntimeException(t);
diff --git a/src/utils/lombok/core/SpiLoadUtil.java b/src/utils/lombok/core/SpiLoadUtil.java
index 02c02496..e685acd6 100644
--- a/src/utils/lombok/core/SpiLoadUtil.java
+++ b/src/utils/lombok/core/SpiLoadUtil.java
@@ -26,6 +26,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.URL;
@@ -108,10 +109,13 @@ public class SpiLoadUtil {
@Override public C next() {
try {
- return target.cast(Class.forName(names.next(), true, fLoader).newInstance());
+ return target.cast(Class.forName(names.next(), true, fLoader).getConstructor().newInstance());
} catch (Exception e) {
- if (e instanceof RuntimeException) throw (RuntimeException)e;
- throw new RuntimeException(e);
+ Throwable t = e;
+ if (t instanceof InvocationTargetException) t = t.getCause();
+ if (t instanceof RuntimeException) throw (RuntimeException) t;
+ if (t instanceof Error) throw (Error) t;
+ throw new RuntimeException(t);
}
}
diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java
index 7a264e39..3cc72f4e 100644
--- a/src/utils/lombok/javac/Javac.java
+++ b/src/utils/lombok/javac/Javac.java
@@ -409,10 +409,14 @@ public class Javac {
} else {
try {
if (CTC_VOID.equals(tag)) {
- return (Type) JC_VOID_TYPE.newInstance();
+ return (Type) JC_VOID_TYPE.getConstructor().newInstance();
} else {
- return (Type) JC_NO_TYPE.newInstance();
+ return (Type) JC_NO_TYPE.getConstructor().newInstance();
}
+ } catch (InvocationTargetException e) {
+ throw sneakyThrow(e.getCause());
+ } catch (NoSuchMethodException e) {
+ throw sneakyThrow(e);
} catch (IllegalAccessException e) {
throw sneakyThrow(e);
} catch (InstantiationException e) {