mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-21 03:24:38 +02:00
8155880: Fix langtools usage of the deprecated Class.newInstance method
Reviewed-by: mcimadamore
This commit is contained in:
parent
2c8f465c47
commit
c52bd6ba1d
5 changed files with 39 additions and 40 deletions
|
@ -125,9 +125,8 @@ public class ToolProvider {
|
||||||
private static <T> T getSystemTool(Class<T> clazz, String moduleName, String className) {
|
private static <T> T getSystemTool(Class<T> clazz, String moduleName, String className) {
|
||||||
if (useLegacy) {
|
if (useLegacy) {
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("deprecation")
|
return Class.forName(className, true, ClassLoader.getSystemClassLoader()).
|
||||||
T result = Class.forName(className, true, ClassLoader.getSystemClassLoader()).asSubclass(clazz).newInstance();
|
asSubclass(clazz).getConstructor().newInstance();
|
||||||
return result;
|
|
||||||
} catch (ReflectiveOperationException e) {
|
} catch (ReflectiveOperationException e) {
|
||||||
throw new Error(e);
|
throw new Error(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -282,9 +283,7 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||||
|
|
||||||
if (options.isSet(XPRINT)) {
|
if (options.isSet(XPRINT)) {
|
||||||
try {
|
try {
|
||||||
@SuppressWarnings("deprecation")
|
processorIterator = List.of(new PrintingProcessor()).iterator();
|
||||||
Processor processor = PrintingProcessor.class.newInstance();
|
|
||||||
processorIterator = List.of(processor).iterator();
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
AssertionError assertError =
|
AssertionError assertError =
|
||||||
new AssertionError("Problem instantiating PrintingProcessor.");
|
new AssertionError("Problem instantiating PrintingProcessor.");
|
||||||
|
@ -540,39 +539,41 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
|
||||||
if (nextProc != null)
|
if (nextProc != null)
|
||||||
return true;
|
return true;
|
||||||
else {
|
else {
|
||||||
if (!names.hasNext())
|
if (!names.hasNext()) {
|
||||||
return false;
|
return false;
|
||||||
else {
|
} else {
|
||||||
String processorName = names.next();
|
Processor processor = getNextProcessor(names.next());
|
||||||
|
if (processor == null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
nextProc = processor;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Processor processor;
|
private Processor getNextProcessor(String processorName) {
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
Class<?> processorClass = processorCL.loadClass(processorName);
|
Class<?> processorClass = processorCL.loadClass(processorName);
|
||||||
ensureReadable(processorClass);
|
ensureReadable(processorClass);
|
||||||
@SuppressWarnings("deprecation")
|
return (Processor) processorClass.getConstructor().newInstance();
|
||||||
Object tmp = processorClass.newInstance();
|
|
||||||
processor = (Processor) tmp;
|
|
||||||
} catch (ClassNotFoundException cnfe) {
|
} catch (ClassNotFoundException cnfe) {
|
||||||
log.error("proc.processor.not.found", processorName);
|
log.error("proc.processor.not.found", processorName);
|
||||||
return false;
|
return null;
|
||||||
} catch (ClassCastException cce) {
|
} catch (ClassCastException cce) {
|
||||||
log.error("proc.processor.wrong.type", processorName);
|
log.error("proc.processor.wrong.type", processorName);
|
||||||
return false;
|
return null;
|
||||||
} catch (Exception e ) {
|
} catch (Exception e ) {
|
||||||
log.error("proc.processor.cant.instantiate", processorName);
|
log.error("proc.processor.cant.instantiate", processorName);
|
||||||
return false;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (ClientCodeException e) {
|
} catch (ClientCodeException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
throw new AnnotationProcessingError(t);
|
throw new AnnotationProcessingError(t);
|
||||||
}
|
}
|
||||||
nextProc = processor;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Processor next() {
|
public Processor next() {
|
||||||
|
|
|
@ -151,8 +151,8 @@ public enum Option {
|
||||||
// Construct transformer
|
// Construct transformer
|
||||||
try {
|
try {
|
||||||
Class<?> trCls = Class.forName(classname);
|
Class<?> trCls = Class.forName(classname);
|
||||||
@SuppressWarnings("deprecation")
|
Transformer transformer =
|
||||||
Transformer transformer = (Transformer) trCls.newInstance();
|
(Transformer) trCls.getConstructor().newInstance();
|
||||||
transformer.setExtra(extra);
|
transformer.setExtra(extra);
|
||||||
helper.addTransformer(suffix, transformer);
|
helper.addTransformer(suffix, transformer);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -252,8 +252,7 @@ public class TagletManager {
|
||||||
}
|
}
|
||||||
tagClassLoader = fileManager.getClassLoader(TAGLET_PATH);
|
tagClassLoader = fileManager.getClassLoader(TAGLET_PATH);
|
||||||
Class<?> customTagClass = tagClassLoader.loadClass(classname);
|
Class<?> customTagClass = tagClassLoader.loadClass(classname);
|
||||||
@SuppressWarnings("deprecation")
|
Object instance = customTagClass.getConstructor().newInstance();
|
||||||
Object instance = customTagClass.newInstance();
|
|
||||||
Taglet newLegacy = new UserTaglet((jdk.javadoc.doclet.taglet.Taglet)instance);
|
Taglet newLegacy = new UserTaglet((jdk.javadoc.doclet.taglet.Taglet)instance);
|
||||||
String tname = newLegacy.getName();
|
String tname = newLegacy.getName();
|
||||||
Taglet t = customTags.get(tname);
|
Taglet t = customTags.get(tname);
|
||||||
|
|
|
@ -273,9 +273,9 @@ public class Start extends ToolOption.Helper {
|
||||||
initMessager();
|
initMessager();
|
||||||
messager.setLocale(locale);
|
messager.setLocale(locale);
|
||||||
try {
|
try {
|
||||||
Object o = docletClass.newInstance();
|
Object o = docletClass.getConstructor().newInstance();
|
||||||
doclet = (Doclet) o;
|
doclet = (Doclet) o;
|
||||||
} catch (InstantiationException | IllegalAccessException exc) {
|
} catch (ReflectiveOperationException exc) {
|
||||||
exc.printStackTrace();
|
exc.printStackTrace();
|
||||||
if (!apiMode) {
|
if (!apiMode) {
|
||||||
error("main.could_not_instantiate_class", docletClass);
|
error("main.could_not_instantiate_class", docletClass);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue