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 2022/04/05 15:40:06 UTC

[groovy] branch GROOVY_4_0_X updated: GROOVY-10565: JDK 17: Sealed classes inside a package causes ClassFormatError

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

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


The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
     new e9ec1c5fd1 GROOVY-10565: JDK 17: Sealed classes inside a package causes ClassFormatError
e9ec1c5fd1 is described below

commit e9ec1c5fd140d1f29844e49ff661d21e41a60462
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Apr 5 21:27:52 2022 +1000

    GROOVY-10565: JDK 17: Sealed classes inside a package causes ClassFormatError
    
    (cherry picked from commit 9bb857ceb3c7f2018127bc2e91110a01bb1f9ec0)
---
 .../groovy/classgen/AsmClassGenerator.java         |  2 +-
 src/test/groovy/bugs/Groovy10565.groovy            | 36 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index c253914f2c..800dc38600 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -379,7 +379,7 @@ public class AsmClassGenerator extends ClassGenerator {
             }
             if (sealedNative(classNode)) {
                 for (ClassNode sub: classNode.getPermittedSubclasses()) {
-                    classVisitor.visitPermittedSubclass(sub.getName());
+                    classVisitor.visitPermittedSubclass(BytecodeHelper.getClassInternalName(sub));
                 }
             }
 
diff --git a/src/test/groovy/bugs/Groovy10565.groovy b/src/test/groovy/bugs/Groovy10565.groovy
new file mode 100644
index 0000000000..3575578753
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy10565.groovy
@@ -0,0 +1,36 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package bugs
+
+import org.codehaus.groovy.classgen.asm.AbstractBytecodeTestCase
+
+import static groovy.test.GroovyAssert.isAtLeastJdk
+
+class Groovy10565 extends AbstractBytecodeTestCase {
+
+    void testPermittedSubclassName() {
+        if (!isAtLeastJdk('17.0')) return
+        def bytecode= compile('''
+            package example
+            sealed class Foo permits Bar { }
+            class Bar extends Foo { }
+        ''')
+        assert bytecode.hasSequence(['PERMITTEDSUBCLASS example/Bar'])
+    }
+}