aboutsummaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authoraclement <aclement>2004-08-10 16:22:01 +0000
committeraclement <aclement>2004-08-10 16:22:01 +0000
commitb75cd93e0de66996397e9f18809973abec91fe46 (patch)
treeb0685fd382e05305bf8342d2e9efea48cf8ced46 /weaver
parent05dabd1821fffd9f353d1e965a56658b962c82d7 (diff)
downloadaspectj-b75cd93e0de66996397e9f18809973abec91fe46.tar.gz
aspectj-b75cd93e0de66996397e9f18809973abec91fe46.zip
Fix for Bugzilla Bug 65319
ajc crashes when compiling the following program (binding this() and target())
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java1
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java4
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/ExposedState.java18
-rw-r--r--weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java21
4 files changed, 41 insertions, 3 deletions
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java
index e35128a62..310e9466a 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java
@@ -291,6 +291,7 @@ public class BcelAdvice extends Advice {
BcelRenderer.renderExpr(fact, world, exposedState.getAspectInstance()));
}
for (int i = 0, len = exposedState.size(); i < len; i++) {
+ if (exposedState.isErroneousVar(i)) continue; // Erroneous vars have already had error msgs reported!
BcelVar v = (BcelVar) exposedState.get(i);
if (v == null) continue;
TypeX desiredTy = getSignature().getParameterTypes()[i];
diff --git a/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java b/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java
index 6cbe6ce56..6b6541758 100644
--- a/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java
+++ b/weaver/src/org/aspectj/weaver/patterns/ArgsPointcut.java
@@ -173,9 +173,11 @@ public class ArgsPointcut extends NameBindingPointcut {
ISourceLocation isl = getSourceLocation();
Message errorMessage = new Message(
"Ambiguous binding of type "+type.getExactType().toString()+
- " using args(..) at this line. Use one args(..) per matched join point,"+"" + " see secondary source location for location of extraneous args(..)",
+ " using args(..) at this line - formal is already bound"+
+ ". See secondary source location for location of args(..)",
shadow.getSourceLocation(),true,new ISourceLocation[]{getSourceLocation()});
shadow.getIWorld().getMessageHandler().handleMessage(errorMessage);
+ state.setErroneousVar(btp.getFormalIndex());
}
}
ret = Test.makeAnd(ret,
diff --git a/weaver/src/org/aspectj/weaver/patterns/ExposedState.java b/weaver/src/org/aspectj/weaver/patterns/ExposedState.java
index 063b5608e..f092ad54d 100644
--- a/weaver/src/org/aspectj/weaver/patterns/ExposedState.java
+++ b/weaver/src/org/aspectj/weaver/patterns/ExposedState.java
@@ -21,11 +21,13 @@ import org.aspectj.weaver.ast.Var;
public class ExposedState {
public Var[] vars;
+ private boolean[] erroneousVars;
private Expr aspectInstance;
public ExposedState(int size) {
super();
vars = new Var[size];
+ erroneousVars = new boolean[size];
}
public ExposedState(Member signature) {
@@ -35,7 +37,11 @@ public class ExposedState {
public void set(int i, Var var) {
//XXX add sanity checks
- // Check (1) added to call of set(), verifies we aren't binding twice to the same formal
+ // Some checks added in ArgsPointcut and ThisOrTargetPointcut
+// if (vars[i]!=null) {
+// if (!var.getType().equals(vars[i].getType()))
+// throw new RuntimeException("Shouldn't allow a slot to change type! Currently="+var.getType()+" New="+vars[i].getType());
+// }
vars[i] = var;
}
public Var get(int i) {
@@ -56,4 +62,14 @@ public class ExposedState {
public String toString() {
return "ExposedState(" + Arrays.asList(vars) + ", " + aspectInstance + ")";
}
+
+ // Set to true if we have reported an error message against it,
+ // prevents us blowing up in later code gen.
+ public void setErroneousVar(int formalIndex) {
+ erroneousVars[formalIndex]=true;
+ }
+
+ public boolean isErroneousVar(int formalIndex) {
+ return erroneousVars[formalIndex];
+ }
}
diff --git a/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java b/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java
index 37d8ac68c..31fe527e3 100644
--- a/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java
+++ b/weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java
@@ -18,6 +18,8 @@ import java.io.DataOutputStream;
import java.io.IOException;
import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.bridge.Message;
import org.aspectj.lang.JoinPoint;
import org.aspectj.util.FuzzyBoolean;
import org.aspectj.weaver.ISourceContext;
@@ -123,7 +125,24 @@ public class ThisOrTargetPointcut extends NameBindingPointcut {
if (type == TypePattern.ANY) return Literal.TRUE;
- Var var = isThis ? shadow.getThisVar() : shadow.getTargetVar();
+ Var var = isThis ? shadow.getThisVar() : shadow.getTargetVar();
+
+ if (type instanceof BindingTypePattern) {
+ BindingTypePattern btp = (BindingTypePattern)type;
+ // Check if we have already bound something to this formal
+ if (state.get(btp.getFormalIndex())!=null) {
+ ISourceLocation pcdSloc = getSourceLocation();
+ ISourceLocation shadowSloc = shadow.getSourceLocation();
+ Message errorMessage = new Message(
+ "Cannot use "+(isThis?"this()":"target()")+" to match at this location and bind a formal to type '"+var.getType()+
+ "' - the formal is already bound to type '"+state.get(btp.getFormalIndex()).getType()+"'"+
+ ". The secondary source location points to the problematic "+(isThis?"this()":"target()")+".",
+ shadowSloc,true,new ISourceLocation[]{pcdSloc});
+ shadow.getIWorld().getMessageHandler().handleMessage(errorMessage);
+ state.setErroneousVar(btp.getFormalIndex());
+ //return null;
+ }
+ }
return exposeStateForVar(var, type, state, shadow.getIWorld());
}