mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-13 20:12:14 +00:00
Remove usages of deprecated (in Java 9 and above) Class#newInstance (#5483)
* Remove usages of deprecated (in Java 9 and above) `Class#newInstance` * Improve catching of InvocationTargetException * Use AssertionError where appropriate
This commit is contained in:
1 parent
10fab8ba91
commit
52acfa962f
13 files changed
+85
-26
No files matched your search
@@ -31,6 +31,7 @@ import hudson.util.CyclicGraphDetector;
|
||||
import hudson.util.CyclicGraphDetector.CycleDetectedException;
|
||||
import hudson.util.IOUtils;
|
||||
import hudson.util.MaskingClassLoader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import jenkins.ClassLoaderReflectionToolkit;
|
||||
import jenkins.ExtensionFilter;
|
||||
import jenkins.plugins.DetachedPluginsUtil;
|
||||
@@ -379,14 +380,14 @@ public class ClassicPluginStrategy implements PluginStrategy {
|
||||
} else {
|
||||
try {
|
||||
Class<?> clazz = wrapper.classLoader.loadClass(className);
|
||||
Object o = clazz.newInstance();
|
||||
Object o = clazz.getDeclaredConstructor().newInstance();
|
||||
if(!(o instanceof Plugin)) {
|
||||
throw new IOException(className+" doesn't extend from hudson.Plugin");
|
||||
}
|
||||
wrapper.setPlugin((Plugin) o);
|
||||
} catch (LinkageError | ClassNotFoundException e) {
|
||||
throw new IOException("Unable to load " + className + " from " + wrapper.getShortName(),e);
|
||||
} catch (IllegalAccessException | InstantiationException e) {
|
||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
throw new IOException("Unable to create instance of " + className + " from " + wrapper.getShortName(),e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user