You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2023/06/11 01:42:28 UTC

[groovy] branch GROOVY_4_0_X updated (6ec511639d -> 093714eb52)

This is an automated email from the ASF dual-hosted git repository.

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


    from 6ec511639d adjust test to account for JEP431 changes
     new e7be46a794 GROOVY-5769: NullObject leak
     new 47daeb188f adjust parameter type to account for JEP431 changes (SequencedCollection mucks up with method distance for DGM#putAt)
     new 093714eb52 adjust test to account for JEP431 changes

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../codehaus/groovy/runtime/DefaultGroovyMethods.java | 19 ++++++++++++++-----
 .../java/org/codehaus/groovy/runtime/NullObject.java  |  3 +++
 .../groovy/ast/tools/WideningCategoriesTest.groovy    |  6 +++---
 .../org/codehaus/groovy/runtime/NullObjectTest.groovy | 18 ++++++++++++++++++
 4 files changed, 38 insertions(+), 8 deletions(-)


[groovy] 01/03: GROOVY-5769: NullObject leak

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e7be46a7944e6b397351d5ff13f6e767a6b8029b
Author: Paul King <pa...@asert.com.au>
AuthorDate: Fri Jun 9 23:55:00 2023 +1000

    GROOVY-5769: NullObject leak
---
 .../java/org/codehaus/groovy/runtime/NullObject.java   |  3 +++
 .../org/codehaus/groovy/runtime/NullObjectTest.groovy  | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/runtime/NullObject.java b/src/main/java/org/codehaus/groovy/runtime/NullObject.java
index 6e68e40b6e..30343852b1 100644
--- a/src/main/java/org/codehaus/groovy/runtime/NullObject.java
+++ b/src/main/java/org/codehaus/groovy/runtime/NullObject.java
@@ -31,6 +31,9 @@ public class NullObject extends GroovyObjectSupport {
      * private constructor
      */
     private NullObject() {
+        if (INSTANCE != null) {
+            throw new RuntimeException("Can't instantiate NullObject. Use NullObject.getNullObject()");
+        }
     }
 
     /**
diff --git a/src/test/org/codehaus/groovy/runtime/NullObjectTest.groovy b/src/test/org/codehaus/groovy/runtime/NullObjectTest.groovy
index 79ba4780a9..bdee23985d 100644
--- a/src/test/org/codehaus/groovy/runtime/NullObjectTest.groovy
+++ b/src/test/org/codehaus/groovy/runtime/NullObjectTest.groovy
@@ -70,6 +70,24 @@ class NullObjectTest extends GroovyTestCase {
         }
     }
 
+    void testInstantiation1() {
+        shouldFail(RuntimeException) {
+            new NullObject()
+        }
+    }
+
+    void testInstantiation2() {
+        shouldFail(RuntimeException) {
+            NullObject.newInstance()
+        }
+    }
+
+    void testInstantiation3() {
+        shouldFail(NoSuchMethodException) {
+            NullObject.getConstructor()
+        }
+    }
+
     void testEMC() {
         def oldMC = null.getMetaClass()
         NullObject.metaClass.hello = { -> "Greeting from null" }


[groovy] 03/03: adjust test to account for JEP431 changes

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 093714eb52de098a0d1fb3e05bbdaaab7a98cd09
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Jun 11 11:39:03 2023 +1000

    adjust test to account for JEP431 changes
---
 .../org/codehaus/groovy/ast/tools/WideningCategoriesTest.groovy     | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/test/org/codehaus/groovy/ast/tools/WideningCategoriesTest.groovy b/src/test/org/codehaus/groovy/ast/tools/WideningCategoriesTest.groovy
index 212588cd4d..6af94aba2e 100644
--- a/src/test/org/codehaus/groovy/ast/tools/WideningCategoriesTest.groovy
+++ b/src/test/org/codehaus/groovy/ast/tools/WideningCategoriesTest.groovy
@@ -231,7 +231,7 @@ final class WideningCategoriesTest extends GenericsTestCase {
 
     void testLUBWithTwoInterfacesAndSingleCommonInterface() {
         ClassNode a = extractTypesFromCode('List<Set> type').type
-        ClassNode b = extractTypesFromCode('List<List> type').type
+        ClassNode b = extractTypesFromCode('List<Queue> type').type
         ClassNode lub = lowestUpperBound(a,b)
         assert lub == LIST_TYPE
         assert lub.genericsTypes.length == 1
@@ -294,14 +294,14 @@ final class WideningCategoriesTest extends GenericsTestCase {
 
     void testCommonAssignableType2() {
         def typeA = extractTypesFromCode('LinkedHashSet type').type
-        def typeB = extractTypesFromCode('List type').type
+        def typeB = extractTypesFromCode('Queue type').type
         def superType = lowestUpperBound(typeA, typeB)
         assert superType == COLLECTION_TYPE
     }
 
     void testCommonAssignableTypeWithGenerics() {
         def typeA = extractTypesFromCode('LinkedHashSet<String> type').type
-        def typeB = extractTypesFromCode('List<String> type').type
+        def typeB = extractTypesFromCode('Queue<String> type').type
         def superType = lowestUpperBound(typeA, typeB)
         assert superType == COLLECTION_TYPE
     }


[groovy] 02/03: adjust parameter type to account for JEP431 changes (SequencedCollection mucks up with method distance for DGM#putAt)

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 47daeb188fbd76a2b415a47c94ab281c14ce742e
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Jun 11 10:28:32 2023 +1000

    adjust parameter type to account for JEP431 changes (SequencedCollection mucks up with method distance for DGM#putAt)
---
 .../codehaus/groovy/runtime/DefaultGroovyMethods.java | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 029c1bd41b..1b537cc059 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -8403,25 +8403,34 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * @since 1.0
      */
     @SuppressWarnings("unchecked")
-    public static void putAt(List self, List splice, List values) {
+    public static void putAt(List self, List splice, Collection values) {
         if (splice.isEmpty()) {
-            if ( ! values.isEmpty() )
-                throw new IllegalArgumentException("Trying to replace 0 elements with "+values.size()+" elements");
+            if (!values.isEmpty())
+                throw new IllegalArgumentException("Trying to replace 0 elements with " + values.size() + " elements");
             return;
         }
         Object first = splice.iterator().next();
         if (first instanceof Integer) {
             if (values.size() != splice.size())
-                throw new IllegalArgumentException("Trying to replace "+splice.size()+" elements with "+values.size()+" elements");
+                throw new IllegalArgumentException("Trying to replace " + splice.size() + " elements with " + values.size() + " elements");
             Iterator<?> valuesIter = values.iterator();
             for (Object index : splice) {
                 putAt(self, (Integer) index, valuesIter.next());
             }
         } else {
-            throw new IllegalArgumentException("Can only index a List with another List of Integers, not a List of "+first.getClass().getName());
+            throw new IllegalArgumentException("Can only index a List with another List of Integers, not a List of " + first.getClass().getName());
         }
     }
 
+    /**
+     * @deprecated use #putAt(List, List, Collection), retained for binary compatibility
+     */
+    @Deprecated
+    @SuppressWarnings("unchecked")
+    public static void putAt(List self, List splice, List values) {
+        putAt(self, splice, (Collection) values);
+    }
+
     /**
      * A helper method to allow lists to work with subscript operators.
      * <pre class="groovyTestCase">def list = ["a", true, 42, 9.4]