aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/javassist/JvstTest5.java
diff options
context:
space:
mode:
authorSam Ma <samuel.ma2012@gmail.com>2019-03-20 13:08:43 +1100
committerSam Ma <samuel.ma2012@gmail.com>2019-03-20 13:08:43 +1100
commite71398c6fc652b8c522da858906a4385cf102130 (patch)
tree8a20ab1b19dc6b404936f5d88c6d3fd7b6b36790 /src/test/javassist/JvstTest5.java
parenteff2f4bbd0246476edfa43782f38e58ddedef952 (diff)
downloadjavassist-e71398c6fc652b8c522da858906a4385cf102130.tar.gz
javassist-e71398c6fc652b8c522da858906a4385cf102130.zip
Fix #252 make instrumentation works on JDK11 for the inner class which has access to the private constructor of the host class
Diffstat (limited to 'src/test/javassist/JvstTest5.java')
-rw-r--r--src/test/javassist/JvstTest5.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java
index 915e1e1a..96f46356 100644
--- a/src/test/javassist/JvstTest5.java
+++ b/src/test/javassist/JvstTest5.java
@@ -14,6 +14,7 @@ import javassist.bytecode.NestMembersAttribute;
import javassist.expr.ExprEditor;
import javassist.expr.Handler;
import javassist.expr.MethodCall;
+import javassist.expr.NewExpr;
@SuppressWarnings({"rawtypes","unchecked","unused"})
public class JvstTest5 extends JvstTestRoot {
@@ -469,6 +470,26 @@ public class JvstTest5 extends JvstTestRoot {
assertEquals(2, invoke(obj, "run"));
}
+ public void testNestPrivateConstructor() throws Exception {
+ CtClass cc = sloader.get("test5.NestHost3$Builder");
+ cc.instrument(new ExprEditor() {
+ public void edit(NewExpr e) throws CannotCompileException {
+ String code = "$_ = $proceed($$);";
+ e.replace(code);
+ }
+ });
+ cc.writeFile();
+ try {
+ Class<?> nestHost3Class = cloader.loadClass("test5.NestHost3");
+ Object builder = nestHost3Class.getDeclaredMethod("builder").invoke(nestHost3Class);
+ Class<?> nestHost3BuilderClass = cloader.loadClass("test5.NestHost3$Builder");
+ nestHost3BuilderClass.getDeclaredMethod("build").invoke(builder);
+ } 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(