aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Bellenger <james.bellenger@airbnb.com>2024-09-17 13:09:36 -0700
committerJames Bellenger <james.bellenger@airbnb.com>2024-09-17 13:17:05 -0700
commit4fd9442a6e3bc2c783daef205a9400596c858dce (patch)
tree2901f98cd0503ff358c9238dbd250e2b6cb98095 /src
parent3cf49c0e6a9a23eb609ef4831782f3f02124975c (diff)
downloadjavassist-4fd9442a6e3bc2c783daef205a9400596c858dce.tar.gz
javassist-4fd9442a6e3bc2c783daef205a9400596c858dce.zip
init
Diffstat (limited to 'src')
-rw-r--r--src/main/javassist/CtClassType.java9
-rw-r--r--src/test/javassist/JvstTest5.java24
2 files changed, 30 insertions, 3 deletions
diff --git a/src/main/javassist/CtClassType.java b/src/main/javassist/CtClassType.java
index f4345e0a..5d3dc5b5 100644
--- a/src/main/javassist/CtClassType.java
+++ b/src/main/javassist/CtClassType.java
@@ -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;
}
diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java
index dce27ab1..cd0158e4 100644
--- a/src/test/javassist/JvstTest5.java
+++ b/src/test/javassist/JvstTest5.java
@@ -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));
+ }
}