You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/06/21 14:57:23 UTC

[groovy] branch danielsun/tweak-build updated: Support JDK17

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

sunlan pushed a commit to branch danielsun/tweak-build
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/danielsun/tweak-build by this push:
     new e7881c2  Support JDK17
e7881c2 is described below

commit e7881c280d7425163a5001c877bd2f7a12315e92
Author: Daniel Sun <su...@apache.org>
AuthorDate: Mon Jun 21 22:54:48 2021 +0800

    Support JDK17
---
 .travis.yml                                        |  2 ++
 .../groovy/runtime/ProxyGeneratorAdapter.java      | 25 +++++++++++++++++++++-
 .../test/groovy/groovy/ant/Groovy8496Test.groovy   |  5 ++++-
 .../test/groovy/groovy/ant/Groovy8497Test.groovy   |  5 ++++-
 4 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index f6a28cd..05a8d44 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -25,6 +25,8 @@ install:
 
 matrix:
   include:
+    - env: BC='indy' FEATURE='17' TARGET_JAVA_HOME="/home/travis/openjdk$FEATURE" LICENSE='GPL'
+      jdk: openjdk11
     - env: BC='indy' FEATURE='16' TARGET_JAVA_HOME="/home/travis/openjdk$FEATURE" LICENSE='GPL'
       jdk: openjdk11
     - env: BC='indy'
diff --git a/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java b/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
index 422ab8a..7ea2a9c 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ProxyGeneratorAdapter.java
@@ -42,6 +42,9 @@ import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Type;
 
 import java.lang.annotation.Annotation;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -210,7 +213,7 @@ public class ProxyGeneratorAdapter extends ClassVisitor {
         this.classList.add(superClass);
         if (generateDelegateField) {
             classList.add(delegateClass);
-            Collections.addAll(this.classList, delegateClass.getInterfaces());
+            Collections.addAll(this.classList, Arrays.stream(delegateClass.getInterfaces()).filter(c -> !isSealed(c)).toArray(Class[]::new));
         }
         if (interfaces != null) {
             Collections.addAll(this.classList, interfaces);
@@ -941,4 +944,24 @@ public class ProxyGeneratorAdapter extends ClassVisitor {
         }
     }
 
+    private static final MethodHandle IS_SEALED_METHODHANDLE;
+    static {
+        MethodHandle mh = null;
+        try {
+            mh = MethodHandles.lookup().findVirtual(Class.class, "isSealed", MethodType.methodType(boolean.class, new Class[0]));
+        } catch (NoSuchMethodException | IllegalAccessException ignored) {
+        }
+        IS_SEALED_METHODHANDLE = mh;
+    }
+
+    private static boolean isSealed(Class<?> clazz) {
+        if (null == IS_SEALED_METHODHANDLE) return false;
+
+        boolean sealed = false;
+        try {
+            sealed = (boolean) IS_SEALED_METHODHANDLE.bindTo(clazz).invokeExact();
+        } catch (Throwable ignored) {
+        }
+        return sealed;
+    }
 }
diff --git a/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8496Test.groovy b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8496Test.groovy
index 981c0a0..3cdd15e 100644
--- a/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8496Test.groovy
+++ b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8496Test.groovy
@@ -18,6 +18,8 @@
  */
 package groovy.ant
 
+import static groovy.test.GroovyAssert.isAtLeastJdk
+
 class Groovy8496Test extends AntTestCase {
     void testGetProperty() {
 //        def debugLogger = new org.apache.tools.ant.DefaultLogger()
@@ -51,7 +53,8 @@ class Groovy8496Test extends AntTestCase {
             ant.groovyc(srcdir: 'src', destdir: 'build')
             ant.javac(classpath: cp, destdir: 'build', srcdir: 'src', includeantruntime: 'false', fork: 'true')
             ant.java(classpath: cp, outputproperty: 'result', classname: 'OverrideGetProperty')
-            assert ant.project.properties.result == 'bar!'
+            // JDK17: 'WARNING: java.lang.System::setSecurityManager is deprecated and will be removed in a future release.\nbar!\nWARNING: java.lang.System::setSecurityManager is deprecated and will be removed in a future release.'
+            assert isAtLeastJdk('17.0') ? ant.project.properties.result.contains('bar!') : ant.project.properties.result == 'bar!'
         }
     }
 }
diff --git a/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8497Test.groovy b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8497Test.groovy
index 1991c2d..886ebd4 100644
--- a/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8497Test.groovy
+++ b/subprojects/groovy-ant/src/test/groovy/groovy/ant/Groovy8497Test.groovy
@@ -18,6 +18,8 @@
  */
 package groovy.ant
 
+import static groovy.test.GroovyAssert.isAtLeastJdk
+
 class Groovy8497Test extends AntTestCase {
     void testGetProperty() {
 //        def debugLogger = new org.apache.tools.ant.DefaultLogger()
@@ -47,7 +49,8 @@ class Groovy8497Test extends AntTestCase {
             ant.groovyc(srcdir: 'src', destdir: 'build')
             ant.javac(classpath: cp, destdir: 'build', srcdir: 'src', includeantruntime: 'false', fork: 'true')
             ant.java(classpath: cp, outputproperty: 'result', classname: 'AccessGetProperty')
-            assert ant.project.properties.result == 'FOO!'
+            // JDK17: 'WARNING: java.lang.System::setSecurityManager is deprecated and will be removed in a future release.\nFOO!\nWARNING: java.lang.System::setSecurityManager is deprecated and will be removed in a future release.'
+            assert isAtLeastJdk('17.0') ? ant.project.properties.result.contains('FOO!') : ant.project.properties.result == 'FOO!'
         }
     }
 }