]> source.dussan.org Git - javassist.git/commitdiff
init 491/head
authorJames Bellenger <james.bellenger@airbnb.com>
Tue, 17 Sep 2024 20:09:36 +0000 (13:09 -0700)
committerJames Bellenger <james.bellenger@airbnb.com>
Tue, 17 Sep 2024 20:17:05 +0000 (13:17 -0700)
src/main/javassist/CtClassType.java
src/test/javassist/JvstTest5.java

index f4345e0a64925255bf6c2cad4c455e92d9d24a01..5d3dc5b53615ff6098ac5e03406fa97f1e6d1f3f 100644 (file)
@@ -932,14 +932,17 @@ class CtClassType extends CtClass {
         ClassFile cf2 = c.getClassFile2();
         InnerClassesAttribute ica = (InnerClassesAttribute)cf.getAttribute(
                                                 InnerClassesAttribute.tag);
+        InnerClassesAttribute ica2 = new InnerClassesAttribute(cf2.getConstPool());
+        int flags = (cf2.getAccessFlags() & ~AccessFlag.SUPER) | AccessFlag.STATIC;
+
         if (ica == null) {
             ica = new InnerClassesAttribute(cf.getConstPool());
             cf.addAttribute(ica);
         }
 
-        ica.append(c.getName(), this.getName(), name,
-                   (cf2.getAccessFlags() & ~AccessFlag.SUPER) | AccessFlag.STATIC);
-        cf2.addAttribute(ica.copy(cf2.getConstPool(), null));
+        ica.append(c.getName(), this.getName(), name, flags);
+        ica2.append(c.getName(), this.getName(), name, flags);
+        cf2.addAttribute(ica2);
         return c;
     }
 
index dce27ab13d7b72bf84a635aa3c0d8a186eec1efa..cd0158e458d8ff8acf380c319b573240f395f8e7 100644 (file)
@@ -643,4 +643,28 @@ public class JvstTest5 extends JvstTestRoot {
         //expected:<Man feed(Bear)> but was:<Keeper feed(Animal)>
         assertEquals(javacResult, javassistResult);
     }
+
+    public void testMultipleNestedClasses() throws Exception {
+        CtClass outer = sloader.makeClass("javassist.MultipleNestedClasses");
+        CtClass nested1 = outer.makeNestedClass("Nested1", true);
+        CtClass nested2 = outer.makeNestedClass("Nested2", true);
+
+        InnerClassesAttribute outerICA = (InnerClassesAttribute)
+                outer.getClassFile2().getAttribute(InnerClassesAttribute.tag);
+        assertEquals(2, outerICA.tableLength());
+        assertEquals("javassist.MultipleNestedClasses$Nested1", outerICA.innerClass(0));
+        assertEquals("javassist.MultipleNestedClasses$Nested2", outerICA.innerClass(1));
+
+        InnerClassesAttribute nested1ICA = (InnerClassesAttribute)
+                nested1.getClassFile2().getAttribute(InnerClassesAttribute.tag);
+        assertEquals(1, nested1ICA.tableLength());
+        assertEquals("javassist.MultipleNestedClasses", nested1ICA.outerClass(0));
+        assertEquals("javassist.MultipleNestedClasses$Nested1", nested1ICA.innerClass(0));
+
+        InnerClassesAttribute nested2ICA = (InnerClassesAttribute)
+                nested2.getClassFile2().getAttribute(InnerClassesAttribute.tag);
+        assertEquals(1, nested2ICA.tableLength());
+        assertEquals("javassist.MultipleNestedClasses", nested2ICA.outerClass(0));
+        assertEquals("javassist.MultipleNestedClasses$Nested2", nested2ICA.innerClass(0));
+    }
 }