You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by jw...@apache.org on 2016/09/22 05:22:50 UTC

[1/2] groovy git commit: Compatibility with Gradle's classloader cleanup (closes #427)

Repository: groovy
Updated Branches:
  refs/heads/master aad354ab6 -> 37161f95e


Compatibility with Gradle's classloader cleanup (closes #427)

Gradle has a cleanup mechanism in place that reflectively accesses
the ClassInfo.klazz field.  This change prevents an exception being
thrown by the cleanup method.  This workaround also means that the
cleanup strategy will no longer work, but the fix to replace klazz with a
WeakReference should eliminate the need for the explicit cleanup.

For more details, see dev mailing list thread:
https://mail-archives.apache.org/mod_mbox/incubator-groovy-dev/201609.mbox/%3CCAHPL-JkQ%2BU8PfaxyVhtE%3DvGV%2BsXXmCzxOsCR8UbBww6P2vskPg%40mail.gmail.com%3E


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

Branch: refs/heads/master
Commit: f42c34bf05afe5385b93464a3b3db1dc2cc122c4
Parents: aad354a
Author: John Wagenleitner <jw...@apache.org>
Authored: Wed Sep 21 22:20:08 2016 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Wed Sep 21 22:20:08 2016 -0700

----------------------------------------------------------------------
 .../codehaus/groovy/reflection/ClassInfo.java   | 24 +++++++++++++++-----
 1 file changed, 18 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/f42c34bf/src/main/org/codehaus/groovy/reflection/ClassInfo.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/reflection/ClassInfo.java b/src/main/org/codehaus/groovy/reflection/ClassInfo.java
index faa5998..b5bf80e 100644
--- a/src/main/org/codehaus/groovy/reflection/ClassInfo.java
+++ b/src/main/org/codehaus/groovy/reflection/ClassInfo.java
@@ -49,7 +49,19 @@ public class ClassInfo implements Finalizable {
     private final LazyClassLoaderRef artifactClassLoader;
     private final LockableObject lock = new LockableObject();
     public final int hash = -1;
-    private final WeakReference<Class<?>> klazz;
+    private final WeakReference<Class<?>> classRef;
+
+    // TODO: should be able to remove the klazz field once 2.5 becomes the mainline release
+    // Gradle has a cleanup mechanism in place to reflectively access this klazz field.
+    // The klazz field is being kept for compatibility so as to not break builds that depend
+    // on versions of Groovy after the field was changed to a WeakReference (classRef).  It
+    // appears that Gradle only performs the cleanup when it detects a groovy version of 2.4.x,
+    // so the klazz field and placeholder Sentinel class can likely be safely removed once
+    // the release version bumps to 2.5 (or beyond).
+    // See:
+    // https://github.com/gradle/gradle/blob/711f64/subprojects/core/src/main/java/org/gradle/api/internal/classloading/LeakyOnJava7GroovySystemLoader.java#L74
+    private static final class Sentinel {}
+    private static final Class<?> klazz = Sentinel.class;
 
     private final AtomicInteger version = new AtomicInteger();
 
@@ -76,7 +88,7 @@ public class ClassInfo implements Finalizable {
     private static final GlobalClassSet globalClassSet = new GlobalClassSet();
 
     ClassInfo(Class klazz) {
-    	this.klazz = new WeakReference<Class<?>>(klazz);
+        this.classRef = new WeakReference<Class<?>>(klazz);
         cachedClassRef = new LazyCachedClassRef(softBundle, this);
         artifactClassLoader = new LazyClassLoaderRef(softBundle, this);
     }
@@ -117,7 +129,7 @@ public class ClassInfo implements Finalizable {
      * @return the {@code Class} associated with this {@code ClassInfo}, else {@code null}
      */
     public final Class<?> getTheClass() {
-        return klazz.get();
+        return classRef.get();
     }
 
     public CachedClass getCachedClass() {
@@ -239,7 +251,7 @@ public class ClassInfo implements Finalizable {
             return answer;
         }
 
-        answer = mccHandle.create(klazz.get(), metaClassRegistry);
+        answer = mccHandle.create(classRef.get(), metaClassRegistry);
         answer.initialize();
 
         if (GroovySystem.isKeepJavaMetaClasses()) {
@@ -403,7 +415,7 @@ public class ClassInfo implements Finalizable {
         }
 
         public CachedClass initValue() {
-            return createCachedClass(info.klazz.get(), info);
+            return createCachedClass(info.classRef.get(), info);
         }
     }
 
@@ -416,7 +428,7 @@ public class ClassInfo implements Finalizable {
         }
 
         public ClassLoaderForClassArtifacts initValue() {
-            return new ClassLoaderForClassArtifacts(info.klazz.get());
+            return new ClassLoaderForClassArtifacts(info.classRef.get());
         }
     }
 


[2/2] groovy git commit: GROOVY-7935: fix style guide example for required parentheses

Posted by jw...@apache.org.
GROOVY-7935: fix style guide example for required parentheses


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

Branch: refs/heads/master
Commit: 37161f95e50abb018bb0c3523aecd948f88555d7
Parents: f42c34b
Author: John Wagenleitner <jw...@apache.org>
Authored: Wed Sep 21 22:20:50 2016 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Wed Sep 21 22:20:50 2016 -0700

----------------------------------------------------------------------
 src/spec/doc/style-guide.adoc | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/37161f95/src/spec/doc/style-guide.adoc
----------------------------------------------------------------------
diff --git a/src/spec/doc/style-guide.adoc b/src/spec/doc/style-guide.adoc
index 240e047..5458d0d 100644
--- a/src/spec/doc/style-guide.adoc
+++ b/src/spec/doc/style-guide.adoc
@@ -209,16 +209,15 @@ list.each  { println it }
 
 Always prefer the third form, which is more natural, as an empty pair of parentheses is just useless syntactical noise!
 
-There are some cases where Groovy doesn't allow you to remove parentheses.
-As I said, top-level expressions can omit them, but for nested method calls or on the right-hand side of an assignment,
-you can't omit them there.
+In some cases parentheses are required, such as when making nested method calls or when calling a method without parameters.
 
 [source,groovy]
 ----
 def foo(n) { n }
+def bar() { 1 }
 
 println foo 1 // won't work
-def m = foo 1
+def m = bar   // won't work
 ----
 
 == Classes as first-class citizens