groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject [groovy] branch master updated: minor refactor: avoid deprecated method usage
Date Wed, 08 May 2019 10:17:23 GMT
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 29115fb  minor refactor: avoid deprecated method usage
29115fb is described below

commit 29115fb7c9fe8eb19de7073b9133a5651686449e
Author: Paul King <paulk@asert.com.au>
AuthorDate: Wed May 8 19:23:18 2019 +1000

    minor refactor: avoid deprecated method usage
---
 src/main/groovy/groovy/grape/Grape.java                          | 5 +++--
 src/main/groovy/groovy/transform/options/PropertyHandler.java    | 6 +-----
 src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java     | 2 +-
 .../groovy/runtime/m12n/StandardPropertiesModuleFactory.java     | 7 ++++---
 .../codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java | 5 +++--
 .../groovy/runtime/typehandling/DefaultTypeTransformation.java   | 2 +-
 .../groovy/transform/ASTTransformationCollectorCodeVisitor.java  | 5 +++--
 .../org/codehaus/groovy/transform/ASTTransformationVisitor.java  | 7 ++++---
 .../org/codehaus/groovy/transform/BuilderASTTransformation.java  | 6 +-----
 .../java/org/codehaus/groovy/transform/LogASTTransformation.java | 4 ++--
 .../groovy/transform/stc/GroovyTypeCheckingExtensionSupport.java | 6 +++---
 .../codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java | 9 +++++----
 src/main/java/org/codehaus/groovy/vmplugin/VMPluginFactory.java  | 2 +-
 src/test/groovy/bugs/Groovy2365Bug.java                          | 4 ++--
 src/test/org/codehaus/groovy/classgen/ForTest.java               | 6 +++---
 src/test/org/codehaus/groovy/classgen/GStringTest.java           | 2 +-
 src/test/org/codehaus/groovy/classgen/GroovyClassLoaderTest.java | 2 +-
 src/test/org/codehaus/groovy/classgen/IfElseTest.java            | 2 +-
 src/test/org/codehaus/groovy/classgen/MethodTest.java            | 2 +-
 src/test/org/codehaus/groovy/classgen/PropertyTest.java          | 4 ++--
 src/test/org/codehaus/groovy/classgen/TestSupport.java           | 2 +-
 src/test/org/codehaus/groovy/classgen/TupleListTest.java         | 2 +-
 subprojects/groovy-jmx/src/test/java/groovy/util/MBeanTest.java  | 2 +-
 .../src/main/java/groovy/servlet/TemplateServlet.java            | 7 ++++---
 .../main/java/org/codehaus/groovy/binding/PropertyBinding.java   | 4 ++--
 .../src/main/groovy/groovy/text/GStringTemplateEngine.java       | 5 +++--
 .../src/main/groovy/groovy/text/StreamingTemplateEngine.java     | 5 +++--
 .../groovy-test/src/main/java/groovy/util/AllTestSuite.java      | 3 +--
 subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java     | 2 +-
 29 files changed, 60 insertions(+), 60 deletions(-)

diff --git a/src/main/groovy/groovy/grape/Grape.java b/src/main/groovy/groovy/grape/Grape.java
index cfa08ad..7ab4328 100644
--- a/src/main/groovy/groovy/grape/Grape.java
+++ b/src/main/groovy/groovy/grape/Grape.java
@@ -18,6 +18,7 @@
  */
 package groovy.grape;
 
+import java.lang.reflect.InvocationTargetException;
 import java.net.URI;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -122,8 +123,8 @@ public class Grape {
             try {
                 // by default use GrapeIvy
                 //TODO META-INF/services resolver?
-                instance = (GrapeEngine) Class.forName("groovy.grape.GrapeIvy").newInstance();
-            } catch (InstantiationException | ClassNotFoundException | IllegalAccessException
e) {
+                instance = (GrapeEngine) Class.forName("groovy.grape.GrapeIvy").getDeclaredConstructor().newInstance();
+            } catch (InstantiationException | ClassNotFoundException | IllegalAccessException
| NoSuchMethodException | InvocationTargetException e) {
                 //LOGME
             }
         }
diff --git a/src/main/groovy/groovy/transform/options/PropertyHandler.java b/src/main/groovy/groovy/transform/options/PropertyHandler.java
index fc9029a..8469a4d 100644
--- a/src/main/groovy/groovy/transform/options/PropertyHandler.java
+++ b/src/main/groovy/groovy/transform/options/PropertyHandler.java
@@ -102,11 +102,7 @@ public abstract class PropertyHandler {
 
         String className = handlerClass.getName();
         try {
-            Object instance = loader.loadClass(className).newInstance();
-            if (instance == null) {
-                xform.addError("Can't load propertyHandler '" + className + "'", anno);
-                return null;
-            }
+            Object instance = loader.loadClass(className).getDeclaredConstructor().newInstance();
             if (!PropertyHandler.class.isAssignableFrom(instance.getClass())) {
                 xform.addError("The propertyHandler class '" + handlerClass.getName() + "'
on " + xform.getAnnotationName() + " is not a propertyHandler", anno);
                 return null;
diff --git a/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java b/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
index 5d5aedf..09c4525 100644
--- a/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
+++ b/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
@@ -458,7 +458,7 @@ public class InvokerHelper {
                 if (Script.class.isAssignableFrom(scriptClass)) {
                     script = newScript(scriptClass, context);
                 } else {
-                    final GroovyObject object = (GroovyObject) scriptClass.newInstance();
+                    final GroovyObject object = (GroovyObject) scriptClass.getDeclaredConstructor().newInstance();
                     // it could just be a class, so let's wrap it in a Script
                     // wrapper; though the bindings will be ignored
                     script = new Script(context) {
diff --git a/src/main/java/org/codehaus/groovy/runtime/m12n/StandardPropertiesModuleFactory.java
b/src/main/java/org/codehaus/groovy/runtime/m12n/StandardPropertiesModuleFactory.java
index 87946a6..3c148b6 100644
--- a/src/main/java/org/codehaus/groovy/runtime/m12n/StandardPropertiesModuleFactory.java
+++ b/src/main/java/org/codehaus/groovy/runtime/m12n/StandardPropertiesModuleFactory.java
@@ -20,6 +20,7 @@ package org.codehaus.groovy.runtime.m12n;
 
 import groovy.lang.GroovyRuntimeException;
 
+import java.lang.reflect.InvocationTargetException;
 import java.util.Properties;
 
 /**
@@ -38,11 +39,11 @@ public class StandardPropertiesModuleFactory extends PropertiesModuleFactory
{
         if (factoryName!=null) {
             try {
                 Class<? extends PropertiesModuleFactory> factoryClass = (Class<?
extends PropertiesModuleFactory>) classLoader.loadClass(factoryName);
-                PropertiesModuleFactory delegate = factoryClass.newInstance();
+                PropertiesModuleFactory delegate = factoryClass.getDeclaredConstructor().newInstance();
                 return delegate.newModule(properties, classLoader);
-            } catch (ClassNotFoundException e) {
+            } catch (ClassNotFoundException | NoSuchMethodException e) {
                 throw new GroovyRuntimeException("Unable to load module factory ["+factoryName+"]",e);
-            } catch (InstantiationException | IllegalAccessException e) {
+            } catch (InstantiationException | IllegalAccessException | InvocationTargetException
e) {
                 throw new GroovyRuntimeException("Unable to instantiate module factory ["+factoryName+"]",e);
             }
         }
diff --git a/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
b/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
index cb8f484..5495b9a 100644
--- a/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
+++ b/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java
@@ -43,6 +43,7 @@ import org.codehaus.groovy.vmplugin.VMPluginFactory;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -254,7 +255,7 @@ public class MetaClassRegistryImpl implements MetaClassRegistry{
 
     private void createMetaMethodFromClass(Map<CachedClass, List<MetaMethod>>
map, Class aClass) {
         try {
-            MetaMethod method = (MetaMethod) aClass.newInstance();
+            MetaMethod method = (MetaMethod) aClass.getDeclaredConstructor().newInstance();
             final CachedClass declClass = method.getDeclaringClass();
             List<MetaMethod> arr = map.get(declClass);
             if (arr == null) {
@@ -263,7 +264,7 @@ public class MetaClassRegistryImpl implements MetaClassRegistry{
             }
             arr.add(method);
             instanceMethods.add(method);
-        } catch (InstantiationException | IllegalAccessException e) { /* ignore */
+        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
| InvocationTargetException e) { /* ignore */
         }
     }
 
diff --git a/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
b/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
index 0fee952..c7fc0a5 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.java
@@ -259,7 +259,7 @@ public class DefaultTypeTransformation {
                 // let's call the collections constructor
                 // passing in the list wrapper
                 try {
-                    answer = (Collection) type.newInstance();
+                    answer = (Collection) type.getDeclaredConstructor().newInstance();
                 } catch (Exception e) {
                     throw new GroovyCastException("Could not instantiate instance of: " +
type.getName() + ". Reason: " + e);
                 }
diff --git a/src/main/java/org/codehaus/groovy/transform/ASTTransformationCollectorCodeVisitor.java
b/src/main/java/org/codehaus/groovy/transform/ASTTransformationCollectorCodeVisitor.java
index d6e8dd5..0ed0f11 100644
--- a/src/main/java/org/codehaus/groovy/transform/ASTTransformationCollectorCodeVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/ASTTransformationCollectorCodeVisitor.java
@@ -39,6 +39,7 @@ import org.codehaus.groovy.transform.trait.TraitASTTransformation;
 import org.codehaus.groovy.transform.trait.Traits;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -219,8 +220,8 @@ public class ASTTransformationCollectorCodeVisitor extends ClassCodeVisitorSuppo
                     Class klass = loadTransformClass(className, aliasNode);
                     if (klass != null) {
                         try {
-                            act = (AnnotationCollectorTransform) klass.newInstance();
-                        } catch (InstantiationException | IllegalAccessException e) {
+                            act = (AnnotationCollectorTransform) klass.getDeclaredConstructor().newInstance();
+                        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
| InvocationTargetException e) {
                             source.getErrorCollector().addErrorAndContinue(new ExceptionMessage(e,
true, source));
                         }
                     }
diff --git a/src/main/java/org/codehaus/groovy/transform/ASTTransformationVisitor.java b/src/main/java/org/codehaus/groovy/transform/ASTTransformationVisitor.java
index 28eee64..696ea5f 100644
--- a/src/main/java/org/codehaus/groovy/transform/ASTTransformationVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/ASTTransformationVisitor.java
@@ -39,6 +39,7 @@ import org.codehaus.groovy.util.URLStreams;
 import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.lang.reflect.InvocationTargetException;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -106,8 +107,8 @@ public final class ASTTransformationVisitor extends ClassCodeVisitorSupport
{
             final Map<Class<? extends ASTTransformation>, ASTTransformation>
transformInstances = new HashMap<Class<? extends ASTTransformation>, ASTTransformation>();
             for (Class<? extends ASTTransformation> transformClass : baseTransforms.keySet())
{
                 try {
-                    transformInstances.put(transformClass, transformClass.newInstance());
-                } catch (InstantiationException | IllegalAccessException e) {
+                    transformInstances.put(transformClass, transformClass.getDeclaredConstructor().newInstance());
+                } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
| InvocationTargetException e) {
                     source.getErrorCollector().addError(
                             new SimpleMessage(
                                     "Could not instantiate Transformation Processor " + transformClass
@@ -309,7 +310,7 @@ public final class ASTTransformationVisitor extends ClassCodeVisitorSupport
{
                     continue;
                 }
                 if (ASTTransformation.class.isAssignableFrom(gTransClass)) {
-                    final ASTTransformation instance = (ASTTransformation)gTransClass.newInstance();
+                    final ASTTransformation instance = (ASTTransformation)gTransClass.getDeclaredConstructor().newInstance();
                     if (instance instanceof CompilationUnitAware) {
                         ((CompilationUnitAware)instance).setCompilationUnit(compilationUnit);
                     }
diff --git a/src/main/java/org/codehaus/groovy/transform/BuilderASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/BuilderASTTransformation.java
index 3f4ea27..7c9964a 100644
--- a/src/main/java/org/codehaus/groovy/transform/BuilderASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/BuilderASTTransformation.java
@@ -255,11 +255,7 @@ public class BuilderASTTransformation extends AbstractASTTransformation
implemen
 
         String className = strategyClass.getName();
         try {
-            Object instance = loader.loadClass(className).newInstance();
-            if (instance == null) {
-                addError("Can't load builderStrategy '" + className + "'", anno);
-                return null;
-            }
+            Object instance = loader.loadClass(className).getDeclaredConstructor().newInstance();
             if (!BuilderStrategy.class.isAssignableFrom(instance.getClass())) {
                 addError("The builderStrategy class '" + strategyClass.getName() + "' on
" + MY_TYPE_NAME + " is not a builderStrategy", anno);
                 return null;
diff --git a/src/main/java/org/codehaus/groovy/transform/LogASTTransformation.java b/src/main/java/org/codehaus/groovy/transform/LogASTTransformation.java
index c2505ff..e0e3b20 100644
--- a/src/main/java/org/codehaus/groovy/transform/LogASTTransformation.java
+++ b/src/main/java/org/codehaus/groovy/transform/LogASTTransformation.java
@@ -244,7 +244,7 @@ public class LogASTTransformation extends AbstractASTTransformation implements
C
             if (AbstractLoggingStrategy.class.isAssignableFrom(strategyClass)) {
                 return DefaultGroovyMethods.newInstance(strategyClass, new Object[]{loader});
             } else {
-                return strategyClass.newInstance();
+                return strategyClass.getDeclaredConstructor().newInstance();
             }
         } catch (Exception e) {
         }
@@ -255,7 +255,7 @@ public class LogASTTransformation extends AbstractASTTransformation implements
C
             if (AbstractLoggingStrategy.class.isAssignableFrom(strategyClass)) {
                 return DefaultGroovyMethods.newInstance(strategyClass, new Object[]{loader});
             } else {
-                return strategyClass.newInstance();
+                return strategyClass.getDeclaredConstructor().newInstance();
             }
         } catch (Exception e) {
             return null;
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/GroovyTypeCheckingExtensionSupport.java
b/src/main/java/org/codehaus/groovy/transform/stc/GroovyTypeCheckingExtensionSupport.java
index dd6ffa3..d456331 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/GroovyTypeCheckingExtensionSupport.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/GroovyTypeCheckingExtensionSupport.java
@@ -129,7 +129,7 @@ public class GroovyTypeCheckingExtensionSupport extends AbstractTypeCheckingExte
         try {
             Class<?> clazz = transformLoader.loadClass(scriptPath, false, true);
             if (TypeCheckingDSL.class.isAssignableFrom(clazz)) {
-                script = (TypeCheckingDSL) clazz.newInstance();
+                script = (TypeCheckingDSL) clazz.getDeclaredConstructor().newInstance();
             } else if (TypeCheckingExtension.class.isAssignableFrom(clazz)) {
                 // since 2.4, we can also register precompiled type checking extensions which
are not scripts
                 try {
@@ -147,9 +147,9 @@ public class GroovyTypeCheckingExtensionSupport extends AbstractTypeCheckingExte
                     );
                 }
             }
-        } catch (ClassNotFoundException e) {
+        } catch (ClassNotFoundException | NoSuchMethodException e) {
             // silent
-        } catch (InstantiationException | IllegalAccessException e) {
+        } catch (InstantiationException | IllegalAccessException | InvocationTargetException
e) {
             addLoadingError(config);
         }
         if (script==null) {
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index 725a013..16cb5a8 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -112,6 +112,7 @@ import org.codehaus.groovy.transform.trait.Traits;
 import org.codehaus.groovy.util.ListHashMap;
 import org.objectweb.asm.Opcodes;
 
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -2985,13 +2986,13 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
             ClassLoader transformLoader = getTransformLoader();
             @SuppressWarnings("unchecked")
             Class<? extends ClosureSignatureHint> hint = (Class<? extends ClosureSignatureHint>)
transformLoader.loadClass(hintClass.getText());
-            ClosureSignatureHint hintInstance = hint.newInstance();
+            ClosureSignatureHint hintInstance = hint.getDeclaredConstructor().newInstance();
             closureSignatures = hintInstance.getClosureSignatures(
                     selectedMethod instanceof ExtensionMethodNode ? ((ExtensionMethodNode)
selectedMethod).getExtensionMethodNode() : selectedMethod,
                     typeCheckingContext.source,
                     typeCheckingContext.compilationUnit,
                     convertToStringArray(options), expression);
-        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException
e) {
+        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException
| NoSuchMethodException | InvocationTargetException e) {
             throw new GroovyBugError(e);
         }
         return closureSignatures;
@@ -3003,7 +3004,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
             ClassLoader transformLoader = getTransformLoader();
             @SuppressWarnings("unchecked")
             Class<? extends ClosureSignatureConflictResolver> resolver = (Class<?
extends ClosureSignatureConflictResolver>) transformLoader.loadClass(resolverClass.getText());
-            ClosureSignatureConflictResolver resolverInstance = resolver.newInstance();
+            ClosureSignatureConflictResolver resolverInstance = resolver.getDeclaredConstructor().newInstance();
             return resolverInstance.resolve(
                     candidates,
                     receiver,
@@ -3013,7 +3014,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport
{
                     typeCheckingContext.source,
                     typeCheckingContext.compilationUnit,
                     convertToStringArray(options));
-        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException
e) {
+        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException
| NoSuchMethodException | InvocationTargetException e) {
             throw new GroovyBugError(e);
         }
     }
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/VMPluginFactory.java b/src/main/java/org/codehaus/groovy/vmplugin/VMPluginFactory.java
index 25a1269..f6cf64a 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/VMPluginFactory.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/VMPluginFactory.java
@@ -54,7 +54,7 @@ public class VMPluginFactory {
         try {
             ClassLoader loader = VMPluginFactory.class.getClassLoader();
             loader.loadClass(classNameCheck);
-            return (VMPlugin) loader.loadClass(pluginName).newInstance();
+            return (VMPlugin) loader.loadClass(pluginName).getDeclaredConstructor().newInstance();
         } catch (Throwable ex) {
             return null;
         }
diff --git a/src/test/groovy/bugs/Groovy2365Bug.java b/src/test/groovy/bugs/Groovy2365Bug.java
index 7e11ace..b70aeec 100644
--- a/src/test/groovy/bugs/Groovy2365Bug.java
+++ b/src/test/groovy/bugs/Groovy2365Bug.java
@@ -49,7 +49,7 @@ public class Groovy2365Bug extends Groovy2365Base {
                     Thread thread1 = new Thread() {
                         public void run() {
                             try {
-                                Script script = (Script) script1Class.newInstance();
+                                Script script = (Script) script1Class.getDeclaredConstructor().newInstance();
                                 script.run();
                                 completed [0] = true;
                             } catch (Exception e) {
@@ -62,7 +62,7 @@ public class Groovy2365Bug extends Groovy2365Base {
                         public void run() {
                             try {
                                 Class cls = groovyLoader.loadClass("Script2", true, true);
-                                Script script = (Script) cls.newInstance();
+                                Script script = (Script) cls.getDeclaredConstructor().newInstance();
                                 script.run();
                                 completed [1] = true;
                             } catch (Exception e) {
diff --git a/src/test/org/codehaus/groovy/classgen/ForTest.java b/src/test/org/codehaus/groovy/classgen/ForTest.java
index 83de44b..165d1a3 100644
--- a/src/test/org/codehaus/groovy/classgen/ForTest.java
+++ b/src/test/org/codehaus/groovy/classgen/ForTest.java
@@ -40,7 +40,7 @@ public class ForTest extends TestSupport {
         Class fooClass = loadClass(classNode);
         assertTrue("Loaded a new class", fooClass != null);
 
-        Object bean = fooClass.newInstance();
+        Object bean = fooClass.getDeclaredConstructor().newInstance();
         assertTrue("Managed to create bean", bean != null);
 
         System.out.println("################ Now about to invoke a method without looping");
@@ -71,7 +71,7 @@ public class ForTest extends TestSupport {
         Class fooClass = loadClass(classNode);
         assertTrue("Loaded a new class", fooClass != null);
 
-        Object bean = fooClass.newInstance();
+        Object bean = fooClass.getDeclaredConstructor().newInstance();
         assertTrue("Managed to create bean", bean != null);
 
         System.out.println("################ Now about to invoke a method with looping");
@@ -103,7 +103,7 @@ public class ForTest extends TestSupport {
         Class fooClass = loadClass(classNode);
         assertTrue("Loaded a new class", fooClass != null);
 
-        Object bean = fooClass.newInstance();
+        Object bean = fooClass.getDeclaredConstructor().newInstance();
         assertTrue("Managed to create bean", bean != null);
 
         System.out.println("################ Now about to invoke a method with many parameters");
diff --git a/src/test/org/codehaus/groovy/classgen/GStringTest.java b/src/test/org/codehaus/groovy/classgen/GStringTest.java
index 4cdaa5d..1513f32 100644
--- a/src/test/org/codehaus/groovy/classgen/GStringTest.java
+++ b/src/test/org/codehaus/groovy/classgen/GStringTest.java
@@ -78,7 +78,7 @@ public class GStringTest extends TestSupport {
         Class fooClass = loadClass(classNode);
         assertTrue("Loaded a new class", fooClass != null);
 
-        Object bean = fooClass.newInstance();
+        Object bean = fooClass.getDeclaredConstructor().newInstance();
         assertTrue("Managed to create bean", bean != null);
 
         //Object[] array = { new Integer(1234), "abc", "def" };
diff --git a/src/test/org/codehaus/groovy/classgen/GroovyClassLoaderTest.java b/src/test/org/codehaus/groovy/classgen/GroovyClassLoaderTest.java
index f7e86a8..76d2f63 100644
--- a/src/test/org/codehaus/groovy/classgen/GroovyClassLoaderTest.java
+++ b/src/test/org/codehaus/groovy/classgen/GroovyClassLoaderTest.java
@@ -34,7 +34,7 @@ public class GroovyClassLoaderTest extends TestSupport {
 
         System.out.println("Invoking main...");
 
-        GroovyObject object = (GroovyObject) groovyClass.newInstance();
+        GroovyObject object = (GroovyObject) groovyClass.getDeclaredConstructor().newInstance();
 
         assertTrue(object != null);
 
diff --git a/src/test/org/codehaus/groovy/classgen/IfElseTest.java b/src/test/org/codehaus/groovy/classgen/IfElseTest.java
index 3622041..7d72581 100644
--- a/src/test/org/codehaus/groovy/classgen/IfElseTest.java
+++ b/src/test/org/codehaus/groovy/classgen/IfElseTest.java
@@ -62,7 +62,7 @@ public class IfElseTest extends TestSupport {
         Class fooClass = loadClass(classNode);
         assertTrue("Loaded a new class", fooClass != null);
 
-        Object bean = fooClass.newInstance();
+        Object bean = fooClass.getDeclaredConstructor().newInstance();
         assertTrue("Managed to create bean", bean != null);
 
         assertSetProperty(bean, "bar", "abc");
diff --git a/src/test/org/codehaus/groovy/classgen/MethodTest.java b/src/test/org/codehaus/groovy/classgen/MethodTest.java
index 8b295f2..6769adc 100644
--- a/src/test/org/codehaus/groovy/classgen/MethodTest.java
+++ b/src/test/org/codehaus/groovy/classgen/MethodTest.java
@@ -46,7 +46,7 @@ public class MethodTest extends TestSupport {
         Class fooClass = loadClass(classNode);
         assertTrue("Loaded a new class", fooClass != null);
 
-        Object bean = fooClass.newInstance();
+        Object bean = fooClass.getDeclaredConstructor().newInstance();
         assertTrue("Created instance of class: " + bean, bean != null);
 
         assertCallMethod(bean, "a", "calledA");
diff --git a/src/test/org/codehaus/groovy/classgen/PropertyTest.java b/src/test/org/codehaus/groovy/classgen/PropertyTest.java
index 187be59..31834ca 100644
--- a/src/test/org/codehaus/groovy/classgen/PropertyTest.java
+++ b/src/test/org/codehaus/groovy/classgen/PropertyTest.java
@@ -48,7 +48,7 @@ public class PropertyTest extends TestSupport {
         Class fooClass = loadClass(classNode);
         assertTrue("Loaded a new class", fooClass != null);
 
-        Object bean = fooClass.newInstance();
+        Object bean = fooClass.getDeclaredConstructor().newInstance();
         assertTrue("Managed to create bean", bean != null);
 
         assertField(fooClass, "bar", 0, ClassHelper.STRING_TYPE);
@@ -64,7 +64,7 @@ public class PropertyTest extends TestSupport {
         Class fooClass = loadClass(classNode);
         assertTrue("Loaded a new class", fooClass != null);
 
-        Object bean = fooClass.newInstance();
+        Object bean = fooClass.getDeclaredConstructor().newInstance();
         assertTrue("Managed to create bean", bean != null);
 
         assertField(fooClass, "bar", 0, ClassHelper.STRING_TYPE);
diff --git a/src/test/org/codehaus/groovy/classgen/TestSupport.java b/src/test/org/codehaus/groovy/classgen/TestSupport.java
index b9b7b87..a984174 100644
--- a/src/test/org/codehaus/groovy/classgen/TestSupport.java
+++ b/src/test/org/codehaus/groovy/classgen/TestSupport.java
@@ -170,7 +170,7 @@ public class TestSupport extends GroovyTestCase implements Opcodes {
 
     protected GroovyObject compile(String fileName) throws Exception {
         Class groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName)));
-        GroovyObject object = (GroovyObject) groovyClass.newInstance();
+        GroovyObject object = (GroovyObject) groovyClass.getDeclaredConstructor().newInstance();
         assertTrue(object != null);
         return object;
     }
diff --git a/src/test/org/codehaus/groovy/classgen/TupleListTest.java b/src/test/org/codehaus/groovy/classgen/TupleListTest.java
index 65a0019..84e1ed7 100644
--- a/src/test/org/codehaus/groovy/classgen/TupleListTest.java
+++ b/src/test/org/codehaus/groovy/classgen/TupleListTest.java
@@ -64,7 +64,7 @@ public class TupleListTest extends TestSupport {
         Class fooClass = loadClass(classNode);
         assertTrue("Loaded a new class", fooClass != null);
 
-        Object bean = fooClass.newInstance();
+        Object bean = fooClass.getDeclaredConstructor().newInstance();
         assertTrue("Managed to create bean", bean != null);
 
         System.out.println("################ Now about to invoke method");
diff --git a/subprojects/groovy-jmx/src/test/java/groovy/util/MBeanTest.java b/subprojects/groovy-jmx/src/test/java/groovy/util/MBeanTest.java
index c71f017..017ae6e 100644
--- a/subprojects/groovy-jmx/src/test/java/groovy/util/MBeanTest.java
+++ b/subprojects/groovy-jmx/src/test/java/groovy/util/MBeanTest.java
@@ -35,7 +35,7 @@ public class MBeanTest extends GroovyTestCase {
         MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
         ObjectName name = new ObjectName("groovy.test:role=TestMBean,type=Dummy");
         // use Class.forName instead of new Dummy() to allow separate compilation
-        mbeanServer.registerMBean(Class.forName("groovy.util.Dummy").newInstance(), name);
+        mbeanServer.registerMBean(Class.forName("groovy.util.Dummy").getDeclaredConstructor().newInstance(),
name);
 
         assertEquals("JMX value of Name", "James", mbeanServer.getAttribute(name, "Name"));
 
diff --git a/subprojects/groovy-servlet/src/main/java/groovy/servlet/TemplateServlet.java
b/subprojects/groovy-servlet/src/main/java/groovy/servlet/TemplateServlet.java
index ba43617..d085d4a 100644
--- a/subprojects/groovy-servlet/src/main/java/groovy/servlet/TemplateServlet.java
+++ b/subprojects/groovy-servlet/src/main/java/groovy/servlet/TemplateServlet.java
@@ -33,6 +33,7 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.Writer;
+import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
 import java.util.Date;
 import java.util.Map;
@@ -385,12 +386,12 @@ public class TemplateServlet extends AbstractHttpServlet {
             return new SimpleTemplateEngine();
         }
         try {
-            return (TemplateEngine) Class.forName(name).newInstance();
-        } catch (InstantiationException e) {
+            return (TemplateEngine) Class.forName(name).getDeclaredConstructor().newInstance();
+        } catch (InstantiationException | InvocationTargetException e) {
             log("Could not instantiate template engine: " + name, e);
         } catch (IllegalAccessException e) {
             log("Could not access template engine class: " + name, e);
-        } catch (ClassNotFoundException e) {
+        } catch (ClassNotFoundException | NoSuchMethodException e) {
             log("Could not find template engine class: " + name, e);
         }
         return null;
diff --git a/subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/PropertyBinding.java
b/subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/PropertyBinding.java
index c577872..47149f5 100644
--- a/subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/PropertyBinding.java
+++ b/subprojects/groovy-swing/src/main/java/org/codehaus/groovy/binding/PropertyBinding.java
@@ -155,8 +155,8 @@ public class PropertyBinding implements SourceBinding, TargetBinding,
TriggerBin
         }
 
         try {
-            return accessorClass.newInstance();
-        } catch (InstantiationException | IllegalAccessException e) {
+            return accessorClass.getDeclaredConstructor().newInstance();
+        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
| InvocationTargetException e) {
             return DefaultPropertyAccessor.INSTANCE;
         }
     }
diff --git a/subprojects/groovy-templates/src/main/groovy/groovy/text/GStringTemplateEngine.java
b/subprojects/groovy-templates/src/main/groovy/groovy/text/GStringTemplateEngine.java
index 1b2fa8c..27c53de 100644
--- a/subprojects/groovy-templates/src/main/groovy/groovy/text/GStringTemplateEngine.java
+++ b/subprojects/groovy-templates/src/main/groovy/groovy/text/GStringTemplateEngine.java
@@ -30,6 +30,7 @@ import org.codehaus.groovy.control.CompilationFailedException;
 
 import java.io.IOException;
 import java.io.Reader;
+import java.lang.reflect.InvocationTargetException;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.Map;
@@ -202,14 +203,14 @@ public class GStringTemplateEngine extends TemplateEngine {
             }
 
             try {
-                final GroovyObject script = (GroovyObject) groovyClass.newInstance();
+                final GroovyObject script = (GroovyObject) groovyClass.getDeclaredConstructor().newInstance();
 
                 this.template = (Closure) script.invokeMethod("getTemplate", null);
                 // GROOVY-6521: must set strategy to DELEGATE_FIRST, otherwise writing
                 // books = 'foo' in a template would store 'books' in the binding of the
template script itself ("script")
                 // instead of storing it in the delegate, which is a Binding too
                 this.template.setResolveStrategy(Closure.DELEGATE_FIRST);
-            } catch (InstantiationException | IllegalAccessException e) {
+            } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
| InvocationTargetException e) {
                 throw new ClassNotFoundException(e.getMessage());
             }
         }
diff --git a/subprojects/groovy-templates/src/main/groovy/groovy/text/StreamingTemplateEngine.java
b/subprojects/groovy-templates/src/main/groovy/groovy/text/StreamingTemplateEngine.java
index 8be0abc..09b8b0c 100644
--- a/subprojects/groovy-templates/src/main/groovy/groovy/text/StreamingTemplateEngine.java
+++ b/subprojects/groovy-templates/src/main/groovy/groovy/text/StreamingTemplateEngine.java
@@ -36,6 +36,7 @@ import java.io.IOException;
 import java.io.LineNumberReader;
 import java.io.Reader;
 import java.io.StringReader;
+import java.lang.reflect.InvocationTargetException;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
@@ -609,11 +610,11 @@ public class StreamingTemplateEngine extends TemplateEngine {
 
             Closure result;
             try {
-                final GroovyObject object = (GroovyObject) groovyClass.newInstance();
+                final GroovyObject object = (GroovyObject) groovyClass.getDeclaredConstructor().newInstance();
                 Closure chicken = (Closure) object.invokeMethod("getTemplate", null);
                 //bind the two first parameters of the generated closure to this class and
the sections list
                 result = chicken.curry(this, sections);
-            } catch (InstantiationException | IllegalAccessException e) {
+            } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
| InvocationTargetException e) {
                 throw new ClassNotFoundException(e.getMessage());
             }
 
diff --git a/subprojects/groovy-test/src/main/java/groovy/util/AllTestSuite.java b/subprojects/groovy-test/src/main/java/groovy/util/AllTestSuite.java
index fe06867..c926003 100644
--- a/subprojects/groovy-test/src/main/java/groovy/util/AllTestSuite.java
+++ b/subprojects/groovy-test/src/main/java/groovy/util/AllTestSuite.java
@@ -92,8 +92,7 @@ public class AllTestSuite extends TestSuite {
     static { // this is only needed since the Groovy Build compiles *.groovy files after
*.java files
         try {
             // TODO: dk: make FileNameFinder injectable
-            Class finderClass = Class.forName("groovy.util.FileNameFinder");
-            finder = (IFileNameFinder) finderClass.newInstance();
+            finder = (IFileNameFinder) Class.forName("groovy.util.FileNameFinder").getDeclaredConstructor().newInstance();
         } catch (Exception e) {
             throw new RuntimeException("Cannot find and instantiate class FileNameFinder",
e);
         }
diff --git a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
index 0594fd1..012769f 100644
--- a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
+++ b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
@@ -409,7 +409,7 @@ public class XmlUtil {
     private static String asString(GPathResult node) {
         // little bit of hackery to avoid Groovy dependency in this file
         try {
-            Object builder = ((Class) Class.forName("groovy.xml.StreamingMarkupBuilder")).newInstance();
+            Object builder = Class.forName("groovy.xml.StreamingMarkupBuilder").getDeclaredConstructor().newInstance();
             InvokerHelper.setProperty(builder, "encoding", "UTF-8");
             Writable w = (Writable) InvokerHelper.invokeMethod(builder, "bindNode", node);
             return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + w.toString();


Mime
View raw message