From: aclement Date: Mon, 23 Oct 2006 11:55:54 +0000 (+0000) Subject: tests and fix for 149908: NPE in org.aspectj.weaver.MemberImpl.getModifiers X-Git-Tag: REMOVING_ASM~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=757004ca6702a97369aac2ba62532f13ac5ced36;p=aspectj.git tests and fix for 149908: NPE in org.aspectj.weaver.MemberImpl.getModifiers --- diff --git a/tests/bugs153/pr149908/A.aj b/tests/bugs153/pr149908/A.aj new file mode 100644 index 000000000..45aa30e7d --- /dev/null +++ b/tests/bugs153/pr149908/A.aj @@ -0,0 +1,6 @@ +public aspect A { + + before() : call(C+.new(..)) { + } + +} diff --git a/tests/bugs153/pr149908/C.java b/tests/bugs153/pr149908/C.java new file mode 100644 index 000000000..7f4f6073f --- /dev/null +++ b/tests/bugs153/pr149908/C.java @@ -0,0 +1,7 @@ +public class C { + + public void foo() { + new MyStringBuilder().append("hello" ," world"); + } + +} diff --git a/tests/bugs153/pr149908/C1.java b/tests/bugs153/pr149908/C1.java new file mode 100644 index 000000000..185afbcd3 --- /dev/null +++ b/tests/bugs153/pr149908/C1.java @@ -0,0 +1,7 @@ +public class C1 { + + public void bar() { + new C(); + } + +} diff --git a/tests/bugs153/pr149908/MyStringBuilder.java b/tests/bugs153/pr149908/MyStringBuilder.java new file mode 100644 index 000000000..36f6deebc --- /dev/null +++ b/tests/bugs153/pr149908/MyStringBuilder.java @@ -0,0 +1,7 @@ +public class MyStringBuilder { + + public void append(String s1, String s2) { + System.out.println("builder: " + s1 + s2); + } + +} diff --git a/tests/bugs153/pr149908/README.txt b/tests/bugs153/pr149908/README.txt new file mode 100644 index 000000000..de367dd27 --- /dev/null +++ b/tests/bugs153/pr149908/README.txt @@ -0,0 +1,26 @@ +This folder contains the code for two tests: + +Case 1: A type that was on the classpath when a jar file was created is + not on the classpath when the aspects are being compiled and woven + with this jar on the inpath. This should result in a cantFindType + message. + +Case 2: The type exists but one of it's members no longer does. This should + result in an unresolvableMember message. + +To recreate required files for Case 1 : + +1. Compile the MyStringBuilder.java in folder pr149908 type: + + javac MyStringBuilder.java + +2. ajc C.java -outjar simple.jar + + +To recreate the required files for Case 2: + +1. Navigate to the withoutMethod folder + +2. Compile MyStringBuilder.java into ..\stringBuilder.jar: + + ajc MyStringBuilder.java -outjar ..\stringBuilder.jar diff --git a/tests/bugs153/pr149908/Tracing.aj b/tests/bugs153/pr149908/Tracing.aj new file mode 100644 index 000000000..0d1f2e5d3 --- /dev/null +++ b/tests/bugs153/pr149908/Tracing.aj @@ -0,0 +1,25 @@ +public aspect Tracing { + + private int _callDepth = -1; + + pointcut tracePoints() : !within(Tracing); + + before() : tracePoints() { + _callDepth++; print("Before", thisJoinPoint); + } + + after() : tracePoints() { + print("After", thisJoinPoint); + _callDepth--; + } + + private void print(String prefix, Object message) { + for(int i = 0, spaces = _callDepth * 2; i < spaces; i++) { + //MyPrint.print(" ",""); + } + + System.out.println(prefix + ": " + message); + } + + +} diff --git a/tests/bugs153/pr149908/simple.jar b/tests/bugs153/pr149908/simple.jar new file mode 100644 index 000000000..16dd602bf Binary files /dev/null and b/tests/bugs153/pr149908/simple.jar differ diff --git a/tests/bugs153/pr149908/stringBuilder.jar b/tests/bugs153/pr149908/stringBuilder.jar new file mode 100644 index 000000000..0586faacd Binary files /dev/null and b/tests/bugs153/pr149908/stringBuilder.jar differ diff --git a/tests/bugs153/pr149908/withoutMethod/MyStringBuilder.java b/tests/bugs153/pr149908/withoutMethod/MyStringBuilder.java new file mode 100644 index 000000000..0a3e6f760 --- /dev/null +++ b/tests/bugs153/pr149908/withoutMethod/MyStringBuilder.java @@ -0,0 +1,3 @@ +public class MyStringBuilder { + +} diff --git a/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java b/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java index 36ab1f60f..e642b4c60 100644 --- a/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java @@ -28,6 +28,8 @@ public class Ajc153Tests extends org.aspectj.testing.XMLBasedAjcTestCase { // public void testCFlowXMLAspectLTW_pr149096() { runTest("cflow xml concrete aspect"); } // public void testAmbiguousBinding_pr121805() { runTest("ambiguous binding");} // public void testNegatedAnnotationMatchingProblem_pr153464() { runTest("negated annotation matching problem");} + public void testNoNPEDueToMissingType_pr149908() { runTest("ensure no npe due to missing type");} + public void testNoNPEDueToMember_pr149908() { runTest("ensure no npe due to missing member");} public void testPTWgetWithinTypeName_pr123423_1() { runTest("basic usage of getWithinTypeName");} public void testPTWgetWithinTypeName_pr123423_2() { runTest("basic usage of getWithinTypeName - multiple types");} public void testPTWgetWithinTypeName_pr123423_3() { runTest("basic usage of getWithinTypeName - non matching types");} diff --git a/tests/src/org/aspectj/systemtest/ajc153/ajc153.xml b/tests/src/org/aspectj/systemtest/ajc153/ajc153.xml index 5243b6168..edf0868e6 100644 --- a/tests/src/org/aspectj/systemtest/ajc153/ajc153.xml +++ b/tests/src/org/aspectj/systemtest/ajc153/ajc153.xml @@ -2,6 +2,19 @@ + + + + + + + + + + + + + diff --git a/weaver/src/org/aspectj/weaver/MemberImpl.java b/weaver/src/org/aspectj/weaver/MemberImpl.java index 469a4b864..cad1e78e0 100644 --- a/weaver/src/org/aspectj/weaver/MemberImpl.java +++ b/weaver/src/org/aspectj/weaver/MemberImpl.java @@ -31,6 +31,9 @@ public class MemberImpl implements Comparable, AnnotatedElement,Member { protected UnresolvedType[] parameterTypes; private final String signature; private String paramSignature; + private boolean reportedCantFindDeclaringType = false; + private boolean reportedUnresolvableMember = false; + /** * All the signatures that a join point with this member as its signature has. @@ -523,14 +526,24 @@ public class MemberImpl implements Comparable, AnnotatedElement,Member { * @see org.aspectj.weaver.Member#getModifiers(org.aspectj.weaver.World) */ public int getModifiers(World world) { - return resolve(world).getModifiers(); + ResolvedMember resolved = resolve(world); + if (resolved == null) { + reportDidntFindMember(world); + return 0; + } + return resolved.getModifiers(); } /* (non-Javadoc) * @see org.aspectj.weaver.Member#getExceptions(org.aspectj.weaver.World) */ public UnresolvedType[] getExceptions(World world) { - return resolve(world).getExceptions(); + ResolvedMember resolved = resolve(world); + if (resolved == null) { + reportDidntFindMember(world); + return UnresolvedType.NONE; + } + return resolved.getExceptions(); } /* (non-Javadoc) @@ -932,7 +945,12 @@ public class MemberImpl implements Comparable, AnnotatedElement,Member { * @see org.aspectj.weaver.Member#getParameterNames(org.aspectj.weaver.World) */ public String[] getParameterNames(World world) { - return resolve(world).getParameterNames(); + ResolvedMember resolved = resolve(world); + if (resolved == null) { + reportDidntFindMember(world); + return null; + } + return resolved.getParameterNames(); } /** @@ -946,5 +964,22 @@ public class MemberImpl implements Comparable, AnnotatedElement,Member { return joinPointSignatures; } + /** + * Raises an [Xlint:cantFindType] message if the declaring type + * cannot be found or an [Xlint:unresolvableMember] message if the + * type can be found (bug 149908) + */ + private void reportDidntFindMember(World world) { + if (reportedCantFindDeclaringType || reportedUnresolvableMember) return; + ResolvedType rType = getDeclaringType().resolve(world); + if (rType.isMissing()) { + world.getLint().cantFindType.signal(WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE,rType.getName()),null); + reportedCantFindDeclaringType = true; + } else { + world.getLint().unresolvableMember.signal(getName(),null); + reportedUnresolvableMember = true; + } + } + }