groovy git commit: GROOVY-7624: Collection asImmutable() methods aren't immutable (closes #672)

2018-03-06 Thread paulk
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X 6152dd304 -> 83d2f1078


GROOVY-7624: Collection asImmutable() methods aren't immutable (closes #672)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/83d2f107
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/83d2f107
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/83d2f107

Branch: refs/heads/GROOVY_2_5_X
Commit: 83d2f1078516f39803c6ef35c412ca24a8270439
Parents: 6152dd3
Author: paulk 
Authored: Tue Mar 6 22:16:29 2018 +1000
Committer: paulk 
Committed: Wed Mar 7 09:06:27 2018 +1000

--
 .../groovy/runtime/DefaultGroovyMethods.java| 162 +++
 1 file changed, 130 insertions(+), 32 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/groovy/blob/83d2f107/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
--
diff --git 
a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java 
b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index c3f0550..f0fe744 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -8131,83 +8131,181 @@ public class DefaultGroovyMethods extends 
DefaultGroovyMethodsSupport {
 }
 
 /**
- * A convenience method for creating an immutable map.
+ * A convenience method for creating an immutable Map.
  *
  * @param self a Map
- * @return an immutable Map
- * @see java.util.Collections#unmodifiableMap(java.util.Map)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asImmutable(java.util.List)
+ * @see #asUnmodifiable(java.util.Map)
  * @since 1.0
  */
-public static  Map asImmutable(Map self) {
-return Collections.unmodifiableMap(self);
+public static  Map asImmutable(Map self) {
+return asUnmodifiable(new LinkedHashMap(self));
 }
 
 /**
- * A convenience method for creating an immutable sorted map.
+ * A convenience method for creating an immutable SortedMap.
  *
  * @param self a SortedMap
- * @return an immutable SortedMap
- * @see java.util.Collections#unmodifiableSortedMap(java.util.SortedMap)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asImmutable(java.util.List)
+ * @see #asUnmodifiable(java.util.SortedMap)
  * @since 1.0
  */
-public static  SortedMap asImmutable(SortedMap self) {
-return Collections.unmodifiableSortedMap(self);
+public static  SortedMap asImmutable(SortedMap self) {
+return asUnmodifiable(new TreeMap(self));
 }
 
 /**
- * A convenience method for creating an immutable list
+ * A convenience method for creating an immutable List.
+ * 
+ * def mutable = [1,2,3]
+ * def immutable = mutable.asImmutable()
+ * try {
+ * immutable << 4
+ * assert false
+ * } catch (UnsupportedOperationException) {
+ * assert true
+ * }
+ * mutable << 4
+ * assert mutable.size() == 4
+ * assert immutable.size() == 3
+ * 
  *
  * @param self a List
- * @return an immutable List
- * @see java.util.Collections#unmodifiableList(java.util.List)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asUnmodifiable(java.util.List)
  * @since 1.0
  */
 public static  List asImmutable(List self) {
-return Collections.unmodifiableList(self);
+return asUnmodifiable(new ArrayList(self));
 }
 
 /**
- * A convenience method for creating an immutable list.
+ * A convenience method for creating an immutable Set.
  *
  * @param self a Set
- * @return an immutable Set
- * @see java.util.Collections#unmodifiableSet(java.util.Set)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asImmutable(java.util.List)
+ * @see #asUnmodifiable(java.util.Set)
  * @since 1.0
  */
 public static  Set asImmutable(Set self) {
-return Collections.unmodifiableSet(self);
+return asUnmodifiable(new LinkedHashSet(self));
 }
 
 /**
- * A convenience method for creating an immutable sorted set.
+ * A convenience method for creating an immutable SortedSet.
  *
  * @param self a SortedSet
- * @return an immutable SortedSet
- * @see java.util.Collections#unmodifiableSortedSet(java.util.SortedSet)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asImmut

groovy git commit: GROOVY-7624: Collection asImmutable() methods aren't immutable (closes #672)

2018-03-06 Thread paulk
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_6_X 2e3de40eb -> 4265c3f26


GROOVY-7624: Collection asImmutable() methods aren't immutable (closes #672)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/4265c3f2
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/4265c3f2
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/4265c3f2

Branch: refs/heads/GROOVY_2_6_X
Commit: 4265c3f264b60d92989dbc332c20bc2d3fff5c99
Parents: 2e3de40
Author: paulk 
Authored: Tue Mar 6 22:16:29 2018 +1000
Committer: paulk 
Committed: Wed Mar 7 09:06:08 2018 +1000

--
 .../groovy/runtime/DefaultGroovyMethods.java| 162 +++
 1 file changed, 130 insertions(+), 32 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/groovy/blob/4265c3f2/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
--
diff --git 
a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java 
b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 8b591f7..274ed8c 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -8133,83 +8133,181 @@ public class DefaultGroovyMethods extends 
DefaultGroovyMethodsSupport {
 }
 
 /**
- * A convenience method for creating an immutable map.
+ * A convenience method for creating an immutable Map.
  *
  * @param self a Map
- * @return an immutable Map
- * @see java.util.Collections#unmodifiableMap(java.util.Map)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asImmutable(java.util.List)
+ * @see #asUnmodifiable(java.util.Map)
  * @since 1.0
  */
-public static  Map asImmutable(Map self) {
-return Collections.unmodifiableMap(self);
+public static  Map asImmutable(Map self) {
+return asUnmodifiable(new LinkedHashMap(self));
 }
 
 /**
- * A convenience method for creating an immutable sorted map.
+ * A convenience method for creating an immutable SortedMap.
  *
  * @param self a SortedMap
- * @return an immutable SortedMap
- * @see java.util.Collections#unmodifiableSortedMap(java.util.SortedMap)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asImmutable(java.util.List)
+ * @see #asUnmodifiable(java.util.SortedMap)
  * @since 1.0
  */
-public static  SortedMap asImmutable(SortedMap self) {
-return Collections.unmodifiableSortedMap(self);
+public static  SortedMap asImmutable(SortedMap self) {
+return asUnmodifiable(new TreeMap(self));
 }
 
 /**
- * A convenience method for creating an immutable list
+ * A convenience method for creating an immutable List.
+ * 
+ * def mutable = [1,2,3]
+ * def immutable = mutable.asImmutable()
+ * try {
+ * immutable << 4
+ * assert false
+ * } catch (UnsupportedOperationException) {
+ * assert true
+ * }
+ * mutable << 4
+ * assert mutable.size() == 4
+ * assert immutable.size() == 3
+ * 
  *
  * @param self a List
- * @return an immutable List
- * @see java.util.Collections#unmodifiableList(java.util.List)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asUnmodifiable(java.util.List)
  * @since 1.0
  */
 public static  List asImmutable(List self) {
-return Collections.unmodifiableList(self);
+return asUnmodifiable(new ArrayList(self));
 }
 
 /**
- * A convenience method for creating an immutable list.
+ * A convenience method for creating an immutable Set.
  *
  * @param self a Set
- * @return an immutable Set
- * @see java.util.Collections#unmodifiableSet(java.util.Set)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asImmutable(java.util.List)
+ * @see #asUnmodifiable(java.util.Set)
  * @since 1.0
  */
 public static  Set asImmutable(Set self) {
-return Collections.unmodifiableSet(self);
+return asUnmodifiable(new LinkedHashSet(self));
 }
 
 /**
- * A convenience method for creating an immutable sorted set.
+ * A convenience method for creating an immutable SortedSet.
  *
  * @param self a SortedSet
- * @return an immutable SortedSet
- * @see java.util.Collections#unmodifiableSortedSet(java.util.SortedSet)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asImmut

groovy git commit: GROOVY-7624: Collection asImmutable() methods aren't immutable (closes #672)

2018-03-06 Thread paulk
Repository: groovy
Updated Branches:
  refs/heads/master 4c5fd9d7e -> d5af9a702


GROOVY-7624: Collection asImmutable() methods aren't immutable (closes #672)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/d5af9a70
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d5af9a70
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d5af9a70

Branch: refs/heads/master
Commit: d5af9a702167a0ef49b1ed2b20d9b97dbbc384f6
Parents: 4c5fd9d
Author: paulk 
Authored: Tue Mar 6 22:16:29 2018 +1000
Committer: paulk 
Committed: Wed Mar 7 09:02:28 2018 +1000

--
 .../groovy/runtime/DefaultGroovyMethods.java| 162 +++
 1 file changed, 130 insertions(+), 32 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/groovy/blob/d5af9a70/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
--
diff --git 
a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java 
b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 8b591f7..274ed8c 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -8133,83 +8133,181 @@ public class DefaultGroovyMethods extends 
DefaultGroovyMethodsSupport {
 }
 
 /**
- * A convenience method for creating an immutable map.
+ * A convenience method for creating an immutable Map.
  *
  * @param self a Map
- * @return an immutable Map
- * @see java.util.Collections#unmodifiableMap(java.util.Map)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asImmutable(java.util.List)
+ * @see #asUnmodifiable(java.util.Map)
  * @since 1.0
  */
-public static  Map asImmutable(Map self) {
-return Collections.unmodifiableMap(self);
+public static  Map asImmutable(Map self) {
+return asUnmodifiable(new LinkedHashMap(self));
 }
 
 /**
- * A convenience method for creating an immutable sorted map.
+ * A convenience method for creating an immutable SortedMap.
  *
  * @param self a SortedMap
- * @return an immutable SortedMap
- * @see java.util.Collections#unmodifiableSortedMap(java.util.SortedMap)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asImmutable(java.util.List)
+ * @see #asUnmodifiable(java.util.SortedMap)
  * @since 1.0
  */
-public static  SortedMap asImmutable(SortedMap self) {
-return Collections.unmodifiableSortedMap(self);
+public static  SortedMap asImmutable(SortedMap self) {
+return asUnmodifiable(new TreeMap(self));
 }
 
 /**
- * A convenience method for creating an immutable list
+ * A convenience method for creating an immutable List.
+ * 
+ * def mutable = [1,2,3]
+ * def immutable = mutable.asImmutable()
+ * try {
+ * immutable << 4
+ * assert false
+ * } catch (UnsupportedOperationException) {
+ * assert true
+ * }
+ * mutable << 4
+ * assert mutable.size() == 4
+ * assert immutable.size() == 3
+ * 
  *
  * @param self a List
- * @return an immutable List
- * @see java.util.Collections#unmodifiableList(java.util.List)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asUnmodifiable(java.util.List)
  * @since 1.0
  */
 public static  List asImmutable(List self) {
-return Collections.unmodifiableList(self);
+return asUnmodifiable(new ArrayList(self));
 }
 
 /**
- * A convenience method for creating an immutable list.
+ * A convenience method for creating an immutable Set.
  *
  * @param self a Set
- * @return an immutable Set
- * @see java.util.Collections#unmodifiableSet(java.util.Set)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asImmutable(java.util.List)
+ * @see #asUnmodifiable(java.util.Set)
  * @since 1.0
  */
 public static  Set asImmutable(Set self) {
-return Collections.unmodifiableSet(self);
+return asUnmodifiable(new LinkedHashSet(self));
 }
 
 /**
- * A convenience method for creating an immutable sorted set.
+ * A convenience method for creating an immutable SortedSet.
  *
  * @param self a SortedSet
- * @return an immutable SortedSet
- * @see java.util.Collections#unmodifiableSortedSet(java.util.SortedSet)
+ * @return an unmodifiable view of a copy of the original, i.e. an 
effectively immutable copy
+ * @see #asImmutable(java.ut