Skip to content
Permalink
Browse files
remove deprecation warnings warning
  • Loading branch information
paulk-asert committed Apr 13, 2022
1 parent e1bbf1e commit df0a7b8b32f6dec6ec714a692c4d5cfcbd882823
Showing 4 changed files with 19 additions and 8 deletions.
@@ -257,8 +257,8 @@ private Object runScriptOrMainOrTestOrRunnable(Class scriptClass, String[] args)
try {
Script script = InvokerHelper.newScript(scriptClass, context);
return script.run();
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
// ignore instantiation errors,, try to do main
} catch (InstantiationException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
// ignore instantiation errors, try to do main
}
}
try {
@@ -22,6 +22,7 @@
import groovy.lang.Closure;
import groovy.lang.DelegatingMetaClass;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyRuntimeException;
import groovy.lang.MetaClass;
import groovy.lang.MissingMethodException;
import groovy.lang.MissingPropertyException;
@@ -659,7 +660,11 @@ public Object newInstance(FactoryBuilderSupport builder, Object name, Object val
if (checkValueIsTypeNotString(value, name, beanClass)) {
return value;
} else {
return beanClass.newInstance();
try {
return beanClass.getDeclaredConstructor().newInstance();
} catch (NoSuchMethodException | InvocationTargetException e) {
throw new GroovyRuntimeException("Failed to register bean factory", e);
}
}
}
});
@@ -20,10 +20,12 @@

import groovy.lang.Closure;
import groovy.lang.GString;
import groovy.lang.GroovyRuntimeException;
import groovy.lang.MetaProperty;
import groovy.lang.MissingPropertyException;
import org.codehaus.groovy.runtime.InvokerHelper;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -452,7 +454,11 @@ public static class DefaultNewInstanceResolver implements NewInstanceResolver {
@Override
public Object newInstance(Class klass, Map attributes) throws InstantiationException,
IllegalAccessException {
return klass.newInstance();
try {
return klass.getDeclaredConstructor().newInstance();
} catch (InvocationTargetException | NoSuchMethodException e) {
throw new GroovyRuntimeException("Unable to create instance resolver", e);
}
}
}

@@ -470,14 +470,14 @@ public Object run() {
return script;
}

public static Script newScript(Class<?> scriptClass, Binding context) throws InstantiationException, IllegalAccessException, InvocationTargetException {
public static Script newScript(Class<? extends Script> scriptClass, Binding context) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
Script script;
try {
Constructor constructor = scriptClass.getConstructor(Binding.class);
script = (Script) constructor.newInstance(context);
Constructor<? extends Script> constructor = scriptClass.getConstructor(Binding.class);
script = constructor.newInstance(context);
} catch (NoSuchMethodException e) {
// Fallback for non-standard "Script" classes.
script = (Script) scriptClass.newInstance();
script = scriptClass.getDeclaredConstructor().newInstance();
script.setBinding(context);
}
return script;

0 comments on commit df0a7b8

Please sign in to comment.