groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emil...@apache.org
Subject [groovy] branch master updated: GROOVY-8423: Do not adjust access modifiers for inner class table
Date Thu, 14 Nov 2019 23:24:08 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 10cebe8  GROOVY-8423: Do not adjust access modifiers for inner class table
10cebe8 is described below

commit 10cebe871a574808f1edb87c73f0c17f73a24e10
Author: Shil Sinha <shils@apache.org>
AuthorDate: Thu Nov 14 17:24:00 2019 -0600

    GROOVY-8423: Do not adjust access modifiers for inner class table
    
    This closes #648
---
 .../groovy/classgen/AsmClassGenerator.java         | 14 +-----
 src/test/gls/innerClass/InnerClassTest.groovy      | 54 +++++++++++++++++++---
 2 files changed, 50 insertions(+), 18 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index a528d3b..bcc140f 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -309,20 +309,11 @@ public class AsmClassGenerator extends ClassGenerator {
             outerClassName = null;
             if (innerClass.isAnonymous()) innerClassName = null;
         }
-        int mods = adjustedClassModifiersForInnerClassTable(cn);
-        if ((mods & ACC_PRIVATE) != 0) {
-            mods ^= ACC_PRIVATE;
-            innerClass.setModifiers(mods);
-        }
-        classVisitor.visitInnerClass(
-                innerClassInternalName,
-                outerClassName,
-                innerClassName,
-                mods);
+        int modifiers = adjustedClassModifiersForInnerClassTable(cn);
+        classVisitor.visitInnerClass(innerClassInternalName, outerClassName, innerClassName,
modifiers);
     }
 
     /*
-     * Classes but not interfaces should have ACC_SUPER set
      * See http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.6-300-D.2-5
      * for what flags are allowed depending on the fact we are writing the inner class table
      * or the class itself
@@ -331,7 +322,6 @@ public class AsmClassGenerator extends ClassGenerator {
         int modifiers = classNode.getModifiers();
         modifiers = modifiers & ~ACC_SUPER;
         modifiers = fixInterfaceModifiers(classNode, modifiers);
-        modifiers = fixInnerClassModifiers(classNode, modifiers);
         return modifiers;
     }
 
diff --git a/src/test/gls/innerClass/InnerClassTest.groovy b/src/test/gls/innerClass/InnerClassTest.groovy
index 7bfd0ab..9f20b7e 100644
--- a/src/test/gls/innerClass/InnerClassTest.groovy
+++ b/src/test/gls/innerClass/InnerClassTest.groovy
@@ -122,19 +122,61 @@ final class InnerClassTest {
         '''
     }
 
+    @Test // GROOVY-8423
+    void testPrivateInnerClassHasPrivateModifier() {
+        assertScript '''
+            import static java.lang.reflect.Modifier.*
+
+            class A {
+                private class B {}
+            }
+
+            int modifiers = A.B.modifiers
+            assert isPrivate(modifiers)
+        '''
+    }
+
+    @Test // GROOVY-8423
+    void testProtectedInnerClassHasProtectedModifier() {
+        assertScript '''
+            import static java.lang.reflect.Modifier.*
+
+            class A {
+                protected class B {}
+            }
+
+            int modifiers = A.B.modifiers
+            assert isProtected(modifiers)
+        '''
+    }
+
+    @Test // GROOVY-8423
+    void testPackagePrivateInnerClassHasProtectedModifier() {
+        assertScript '''
+            import static java.lang.reflect.Modifier.*
+
+            class A {
+                @groovy.transform.PackageScope class B {}
+            }
+
+            int modifiers = A.B.modifiers
+            assert !isPrivate(modifiers) && !isProtected(modifiers) && !isPublic(modifiers)
+        '''
+    }
+
     @Test
     void testStaticInnerClass() {
         assertScript '''
-            import java.lang.reflect.Modifier
+            import static java.lang.reflect.Modifier.*
 
             class A {
-                static class B{}
+                static class B {}
             }
-            def x = new A.B()
-            assert x != null
+            def b = new A.B()
+            assert b != null
 
-            def mods = A.B.modifiers
-            assert Modifier.isPublic(mods)
+            int modifiers = A.B.modifiers
+            assert isPublic(modifiers)
         '''
     }
 


Mime
View raw message