diff options
author | chibash <chiba@javassist.org> | 2015-05-25 02:37:05 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2015-05-25 02:37:05 +0900 |
commit | efae59551e3a95cf128fbac60b6fcfee4d2cf2ce (patch) | |
tree | dbc87d2214c61744f7fd87cff3c23cedab89dd01 /src | |
parent | bbecd7c489662c68af12b0e56265d52b7b2a644d (diff) | |
download | javassist-efae59551e3a95cf128fbac60b6fcfee4d2cf2ce.tar.gz javassist-efae59551e3a95cf128fbac60b6fcfee4d2cf2ce.zip |
fixed a bug reported as JASSIST-246
Diffstat (limited to 'src')
-rw-r--r-- | src/main/javassist/compiler/MemberResolver.java | 39 | ||||
-rw-r--r-- | src/test/javassist/JvstTest5.java | 14 | ||||
-rw-r--r-- | src/test/test5/JIRA246.java | 21 |
3 files changed, 54 insertions, 20 deletions
diff --git a/src/main/javassist/compiler/MemberResolver.java b/src/main/javassist/compiler/MemberResolver.java index c232ccda..ddbe1be4 100644 --- a/src/main/javassist/compiler/MemberResolver.java +++ b/src/main/javassist/compiler/MemberResolver.java @@ -139,30 +139,29 @@ public class MemberResolver implements TokenId { } catch (NotFoundException e) {} - if (isIntf || Modifier.isAbstract(mod)) - try { - CtClass[] ifs = clazz.getInterfaces(); - int size = ifs.length; - for (int i = 0; i < size; ++i) { - Method r = lookupMethod(ifs[i], methodName, - argTypes, argDims, argClassNames, - onlyExact); + try { + CtClass[] ifs = clazz.getInterfaces(); + int size = ifs.length; + for (int i = 0; i < size; ++i) { + Method r = lookupMethod(ifs[i], methodName, + argTypes, argDims, argClassNames, + onlyExact); + if (r != null) + return r; + } + + if (isIntf) { + // finally search java.lang.Object. + CtClass pclazz = clazz.getSuperclass(); + if (pclazz != null) { + Method r = lookupMethod(pclazz, methodName, argTypes, + argDims, argClassNames, onlyExact); if (r != null) return r; } - - if (isIntf) { - // finally search java.lang.Object. - CtClass pclazz = clazz.getSuperclass(); - if (pclazz != null) { - Method r = lookupMethod(pclazz, methodName, argTypes, - argDims, argClassNames, onlyExact); - if (r != null) - return r; - } - } } - catch (NotFoundException e) {} + } + catch (NotFoundException e) {} return maybe; } diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index 124f585d..097dcd4d 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -53,4 +53,18 @@ public class JvstTest5 extends JvstTestRoot { Object obj = make(cc.getName()); assertEquals(10, invoke(obj, "run")); } + + public void testJIRA246() throws Exception { + CtClass ctClass = sloader.makeClass("test5.JIRA246Test"); + ctClass.addInterface(sloader.get(test5.JIRA246.Test.class.getName())); + String methodBody = "public void test() { defaultMethod(); }"; + CtMethod ctMethod = CtMethod.make(methodBody, ctClass); + ctClass.addMethod(ctMethod); + } + + public void testJIRA246b() throws Exception { + CtClass ctClass = sloader.get(test5.JIRA246.A.class.getName()); + String src = "public void id() { get(); }"; + CtMethod make = CtNewMethod.make(src, ctClass); + } } diff --git a/src/test/test5/JIRA246.java b/src/test/test5/JIRA246.java new file mode 100644 index 00000000..da23f6ea --- /dev/null +++ b/src/test/test5/JIRA246.java @@ -0,0 +1,21 @@ +package test5; + +public class JIRA246 { + public interface Test { + default void defaultMethod() { + } + void test(); + } + + public interface IA { + default int get() { + return 0; + } + } + + public static class A implements IA { + public int anotherGet() { + return 1; + } + } +} |