From 757004ca6702a97369aac2ba62532f13ac5ced36 Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 23 Oct 2006 11:55:54 +0000 Subject: [PATCH] tests and fix for 149908: NPE in org.aspectj.weaver.MemberImpl.getModifiers --- tests/bugs153/pr149908/A.aj | 6 +++ tests/bugs153/pr149908/C.java | 7 +++ tests/bugs153/pr149908/C1.java | 7 +++ tests/bugs153/pr149908/MyStringBuilder.java | 7 +++ tests/bugs153/pr149908/README.txt | 26 +++++++++++ tests/bugs153/pr149908/Tracing.aj | 25 +++++++++++ tests/bugs153/pr149908/simple.jar | Bin 0 -> 655 bytes tests/bugs153/pr149908/stringBuilder.jar | Bin 0 -> 551 bytes .../withoutMethod/MyStringBuilder.java | 3 ++ .../systemtest/ajc153/Ajc153Tests.java | 2 + .../org/aspectj/systemtest/ajc153/ajc153.xml | 13 ++++++ weaver/src/org/aspectj/weaver/MemberImpl.java | 41 ++++++++++++++++-- 12 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 tests/bugs153/pr149908/A.aj create mode 100644 tests/bugs153/pr149908/C.java create mode 100644 tests/bugs153/pr149908/C1.java create mode 100644 tests/bugs153/pr149908/MyStringBuilder.java create mode 100644 tests/bugs153/pr149908/README.txt create mode 100644 tests/bugs153/pr149908/Tracing.aj create mode 100644 tests/bugs153/pr149908/simple.jar create mode 100644 tests/bugs153/pr149908/stringBuilder.jar create mode 100644 tests/bugs153/pr149908/withoutMethod/MyStringBuilder.java 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 0000000000000000000000000000000000000000..16dd602bfaac21e9a1f809080644def023f4927f GIT binary patch literal 655 zcmWIWW@Zs#-~d9?a2HbsBp|}T!r-O&y1H)(EGpBvL zb@eXtdh2SPJ9B<>kiiw>2TzOiynJ;$eJ_@-+7eWtqvzqP_c5s8+|) zi6Ow7onzCL@GeWBMdm;p0Jq)@&3bmAtg~KnPGWI!>V(sNha5!O{y)4HbeW6HB zy;IB!^wt!HmNY6BT5eJ1St)BI($W9aO~|)~LH<-lR8OqM$({3Sp3nLDtL{I`gGVim zm248uxo4j5k^NY4W1oDF>jVi6qY%9moypp5Nt>^xYgB59giZag8xm`6@3q6y|6@SEJY}cMNkt^Rt zpzy5l%13kj7VpyE>vFoH!gg|?#+JretyQ~RDpeMF%)GIv)?eJqePO5Ur=KZGk0v}^ z^YZ!ewGwmx&kWn&W&39N8D_TC%hRj`wj0Inf3!2xT1w->&6nB@OZPk6TCl=*+C<&? z`WwH^nyPzgs?Ny`e!F&MDeRv3)NEx`gYQ1iAeGFN72cmN`~7DAdR$c|{r1h;!-;%b zPc&`2p%THj?f(Jy$mbvVLBW3`PPWO5k%8e65C?cOGKnxC;vYF`K=F?XaHR%hQ$W#( fYy&775uhH(ghpzBH!B-Rf(Zz#f%HG1a~K!^^u_1^ literal 0 HcmV?d00001 diff --git a/tests/bugs153/pr149908/stringBuilder.jar b/tests/bugs153/pr149908/stringBuilder.jar new file mode 100644 index 0000000000000000000000000000000000000000..0586faacd843ad1558ac445fb20c026bfd41c0bd GIT binary patch literal 551 zcmWIWW@Zs#-~d9$G8a<@Bp|}T!r-O&y1H)(EGpBvL zb@eXtdh2SPJ9B<>kiiw>2TzOiynJ;$eJ_@-+7eWtqvzqP_c5s8+|) zi6Ow7onzCL@GeWBMdm;pfYW+Wpsa6Ya7j^SUb<6hW==|KkzR66VsUY--)X*s0Rpzp zTdzd_X^<8B#dxIY$f^i|-?w)?^xAszs#ndlsYed6|IjehU42gF`8mttqVs#~&x$H@Y zL9T?x=kRr0Pqi$ogYsL&J)DmB)(F073Df-F?N$>a?sWUCYCq>UHLorD;#yxzi+=}J ziBxG6L`5Ar`>;pMSpBg><`0Lb=bRbM7SHT#(Mo=s{$TsO%-%Cs|1g09B1c3-{}|Al ze2k!gU}O?uK*R)cAc0~672t{&bW@OR00k%l)B~AVgEzpNl?|kf2?#rZbO+FJ3=9AZ CNUc2p literal 0 HcmV?d00001 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; + } + } + } -- 2.39.5