mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 08:15:48 +00:00
[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).
This commit is contained in:
1 parent
2335f25166
commit
d41e804fe7
5 files changed
+19
-9
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user