diff options
author | shifujun <shifujun@foxmail.com> | 2023-12-08 14:48:28 +0800 |
---|---|---|
committer | shifujun <shifujun@foxmail.com> | 2023-12-08 17:18:27 +0800 |
commit | c04c375e813597eaeb305a641f58a89fe665ea54 (patch) | |
tree | 0ce0674728ec2a0b4a2c1d35d33dfa81a5cea3cc /src/test/javassist/JvstTest5.java | |
parent | 158294371e39b24f003f15933bd74f2b26bbf3aa (diff) | |
download | javassist-c04c375e813597eaeb305a641f58a89fe665ea54.tar.gz javassist-c04c375e813597eaeb305a641f58a89fe665ea54.zip |
Fix MemberResolver.lookupMethod bug when super class has more precise match
When onlyExact=false and super class have a more precise match,
it should not return with current class's maybe result.
New added testSuperCall reveals the problem.
Diffstat (limited to 'src/test/javassist/JvstTest5.java')
-rw-r--r-- | src/test/javassist/JvstTest5.java | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index f1c56837..561181c3 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.lang.annotation.Annotation; +import java.lang.reflect.Method; import java.lang.reflect.TypeVariable; import javassist.bytecode.AccessFlag; @@ -166,7 +167,7 @@ public class JvstTest5 extends JvstTestRoot { CtClass cc = sloader.makeClass("test5.JIRA256"); ClassFile ccFile = cc.getClassFile(); ConstPool constpool = ccFile.getConstPool(); - + AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag); javassist.bytecode.annotation.Annotation entityAnno = new javassist.bytecode.annotation.Annotation("test5.Entity", constpool); @@ -181,7 +182,7 @@ public class JvstTest5 extends JvstTestRoot { assertTrue(o.getClass().getName().equals("test5.JIRA256")); java.lang.annotation.Annotation[] annotations = o.getClass().getDeclaredAnnotations(); - assertEquals(1, annotations.length); + assertEquals(1, annotations.length); } public void testJIRA250() throws Exception { @@ -625,4 +626,24 @@ public class JvstTest5 extends JvstTestRoot { assertEquals(1, attr.size()); assertNull(attr.parameterName(0)); } + + public void testSuperCall() throws Exception { + String javacResult = new BearKeeper().javacResult(); + assertEquals("Man feed(Bear)", javacResult); + + CtClass cc = sloader.get("javassist.BearKeeper"); + CtMethod cm = CtMethod.make( + "public String javassistResult() {return super.feed(new javassist.Bear());}", + cc); + cc.addMethod(cm); + cc.setModifiers(Modifier.PUBLIC); + cc.writeFile(); + Object obj = make(cc.getName()); + Method m = obj.getClass().getMethod("javassistResult"); + Object javassistResult = m.invoke(obj); + + //before this fix + //expected:<Man feed(Bear)> but was:<Keeper feed(Animal)> + assertEquals(javacResult, javassistResult); + } } |