From 331399f82b33cc4cff8239aab18e405dfe0dd2b9 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Fri, 4 Apr 2014 12:33:45 -0700 Subject: [PATCH] Fix 431976: thisJoinPoint considered uninitialized variable --- .../compiler/problem/AjProblemReporter.java | 13 +++++++++++++ tests/bugs180/pr431976/Code.java | 10 ++++++++++ .../org/aspectj/systemtest/ajc180/Ajc180Tests.java | 4 ++++ tests/src/org/aspectj/systemtest/ajc180/ajc180.xml | 4 ++++ 4 files changed, 31 insertions(+) create mode 100644 tests/bugs180/pr431976/Code.java diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java index 31d9d149a..4f0dc27e0 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java @@ -21,6 +21,7 @@ import java.util.Iterator; import java.util.List; import java.util.Set; +import org.aspectj.ajdt.internal.compiler.ast.AdviceDeclaration; import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration; import org.aspectj.ajdt.internal.compiler.ast.DeclareAnnotationDeclaration; import org.aspectj.ajdt.internal.compiler.ast.PointcutDeclaration; @@ -48,6 +49,7 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.aspectj.org.eclipse.jdt.internal.compiler.impl.ReferenceContext; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ArrayBinding; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.IPrivilegedHandler; +import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.MethodBinding; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ParameterizedMethodBinding; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; @@ -506,6 +508,17 @@ public class AjProblemReporter extends ProblemReporter { } super.unusedPrivateType(typeDecl); } + private final static char[] thisJoinPointName = "thisJoinPoint".toCharArray(); + + public void uninitializedLocalVariable(LocalVariableBinding binding, ASTNode location) { + if (CharOperation.equals(binding.name,thisJoinPointName)) { + // If in advice, this is not a problem + if (binding.declaringScope!=null && binding.declaringScope.referenceContext() instanceof AdviceDeclaration) { + return; + } + } + super.uninitializedLocalVariable(binding, location); + } public void abstractMethodInConcreteClass(SourceTypeBinding type) { if (type.scope!=null && type.scope.referenceContext instanceof AspectDeclaration) { diff --git a/tests/bugs180/pr431976/Code.java b/tests/bugs180/pr431976/Code.java new file mode 100644 index 000000000..a58ea4ecc --- /dev/null +++ b/tests/bugs180/pr431976/Code.java @@ -0,0 +1,10 @@ +import org.aspectj.lang.annotation.SuppressAjWarnings; + +privileged aspect BugThisJoinPoint { + + @SuppressAjWarnings("adviceDidNotMatch") + void around(): execution(boolean forceFocus ()) { + thisJoinPoint.getThis(); + } +} + diff --git a/tests/src/org/aspectj/systemtest/ajc180/Ajc180Tests.java b/tests/src/org/aspectj/systemtest/ajc180/Ajc180Tests.java index ea5d1c845..3da1f12b6 100644 --- a/tests/src/org/aspectj/systemtest/ajc180/Ajc180Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc180/Ajc180Tests.java @@ -21,6 +21,10 @@ import org.aspectj.testing.XMLBasedAjcTestCase; */ public class Ajc180Tests extends org.aspectj.testing.XMLBasedAjcTestCase { + public void testThisJoinPointNotInitialized_431976() { + runTest("thisJoinPoint not initialized"); + } + public void testNullAnnotationMatching_431541() { runTest("NullAnnotationMatching exception"); } diff --git a/tests/src/org/aspectj/systemtest/ajc180/ajc180.xml b/tests/src/org/aspectj/systemtest/ajc180/ajc180.xml index 0d1132de6..6f7b0c586 100644 --- a/tests/src/org/aspectj/systemtest/ajc180/ajc180.xml +++ b/tests/src/org/aspectj/systemtest/ajc180/ajc180.xml @@ -2,6 +2,10 @@ + + + + -- 2.39.5