Skip to content

Commit

Permalink
[trivial] replacing all calls to Class.newInstance() with Class.getCo…
Browse files Browse the repository at this point in the history
…nstructor().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).
  • Loading branch information
rzwitserloot committed May 6, 2019
1 parent 2335f25 commit d41e804
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/core/lombok/core/AgentLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,9 +36,10 @@ public static void runAgents(String agentArgs, Instrumentation instrumentation,
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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/lombok/core/AnnotationProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static class JavacDescriptor extends ProcessorDescriptor {

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;
Expand Down
4 changes: 2 additions & 2 deletions src/delombok/lombok/delombok/ant/DelombokTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void execute() throws BuildException {
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());
Expand All @@ -208,7 +208,7 @@ public void execute() throws BuildException {
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);
Expand Down
10 changes: 7 additions & 3 deletions src/utils/lombok/core/SpiLoadUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;
Expand Down Expand Up @@ -108,10 +109,13 @@ public static <C> Iterable<C> findServices(final Class<C> target, ClassLoader lo

@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);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/utils/lombok/javac/Javac.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,14 @@ public static Type createVoidType(Symtab symbolTable, TypeTag tag) {
} 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) {
Expand Down

0 comments on commit d41e804

Please sign in to comment.