From d6d6b2e959d3758f69b2917587b16453d7fc6ec5 Mon Sep 17 00:00:00 2001 From: Sam Ma Date: Tue, 23 Jul 2019 21:35:24 +1000 Subject: Fix #265 javassist.CannotCompileException: [source error] the called constructor is private --- src/test/javassist/JvstTest5.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/test/javassist/JvstTest5.java') 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( -- cgit v1.2.3