diff options
author | Sam Ma <samuel.ma2012@gmail.com> | 2019-07-23 21:35:24 +1000 |
---|---|---|
committer | Sam Ma <samuel.ma2012@gmail.com> | 2019-07-23 21:35:24 +1000 |
commit | d6d6b2e959d3758f69b2917587b16453d7fc6ec5 (patch) | |
tree | 9bbd4db896f3adb9291999e619620aa33ff04de3 /src/test | |
parent | 9076bde17537c059aa679bd6c0324bda78bdb088 (diff) | |
download | javassist-d6d6b2e959d3758f69b2917587b16453d7fc6ec5.tar.gz javassist-d6d6b2e959d3758f69b2917587b16453d7fc6ec5.zip |
Fix #265 javassist.CannotCompileException: [source error] the called constructor is private
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/javassist/JvstTest5.java | 27 | ||||
-rw-r--r-- | src/test/test5/NestHost4.java | 26 |
2 files changed, 53 insertions, 0 deletions
diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index 96f46356..4d4fc719 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -490,6 +490,33 @@ public class JvstTest5 extends JvstTestRoot { } } + public void testNestPrivateConstructor2() throws Exception { + CtClass cc = sloader.get("test5.NestHost4$InnerClass1"); + cc.instrument(new ExprEditor() { + public void edit(NewExpr e) throws CannotCompileException { + String code = "$_ = $proceed($$);"; + e.replace(code); + } + }); + cc.writeFile(); + + cc = sloader.get("test5.NestHost4$InnerClass1$InnerClass5"); + cc.instrument(new ExprEditor() { + public void edit(NewExpr e) throws CannotCompileException { + String code = "$_ = $proceed($$);"; + e.replace(code); + } + }); + cc.writeFile(); + try { + Class<?> nestHost4Class = cloader.loadClass("test5.NestHost4"); + nestHost4Class.getDeclaredConstructor().newInstance(); + } catch (Exception ex) { + ex.printStackTrace(); + fail("it should be able to access the private constructor of the nest host"); + } + } + public void testSwitchCaseWithStringConstant2() throws Exception { CtClass cc = sloader.makeClass("test5.SwitchCase2"); cc.addMethod(CtNewMethod.make( diff --git a/src/test/test5/NestHost4.java b/src/test/test5/NestHost4.java new file mode 100644 index 00000000..a8d60f05 --- /dev/null +++ b/src/test/test5/NestHost4.java @@ -0,0 +1,26 @@ +package test5; + +public class NestHost4 { + public void test() { + new InnerClass1().new InnerClass5(); + } + + private class InnerClass1 { + private InnerClass1() { + new InnerClass2(); + } + + private class InnerClass5 { + private InnerClass5() { + new InnerClass2().new InnerClass3(); + } + } + } + + private class InnerClass2 { + + private class InnerClass3 { + + } + } +} |