From 6e423f15e29896cf3be78b37c72c3b422e171c71 Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 3 Nov 2005 15:24:48 +0000 Subject: [PATCH] test and fix for 86903 --- tests/bugs150/pr86903/BadWormhole.java | 11 +++++++++++ tests/bugs150/pr86903/GenericService.java | 4 ++++ tests/bugs150/pr86903/Main.java | 6 ++++++ tests/bugs150/pr86903/Service.java | 8 ++++++++ weaver/src/org/aspectj/weaver/IntMap.java | 9 +++------ .../aspectj/weaver/patterns/CflowPointcut.java | 18 ++++++++++++++++-- .../aspectj/weaver/patterns/IfPointcut.java | 4 ++-- 7 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 tests/bugs150/pr86903/BadWormhole.java create mode 100644 tests/bugs150/pr86903/GenericService.java create mode 100644 tests/bugs150/pr86903/Main.java create mode 100644 tests/bugs150/pr86903/Service.java diff --git a/tests/bugs150/pr86903/BadWormhole.java b/tests/bugs150/pr86903/BadWormhole.java new file mode 100644 index 000000000..6d14b4980 --- /dev/null +++ b/tests/bugs150/pr86903/BadWormhole.java @@ -0,0 +1,11 @@ + +aspect BadWormhole { + + pointcut isDynamicService(Main mm,Service s): + cflowbelow(this(mm)) && + if(true==true) && + this(s); + + //before(Main mm,Service s): isDynamicService(mm,s) {} + before(Service s): isDynamicService(*,s) {} +} diff --git a/tests/bugs150/pr86903/GenericService.java b/tests/bugs150/pr86903/GenericService.java new file mode 100644 index 000000000..3c6950875 --- /dev/null +++ b/tests/bugs150/pr86903/GenericService.java @@ -0,0 +1,4 @@ + +public interface GenericService { + public abstract void setContext(String localCtx); +} diff --git a/tests/bugs150/pr86903/Main.java b/tests/bugs150/pr86903/Main.java new file mode 100644 index 000000000..7122a2925 --- /dev/null +++ b/tests/bugs150/pr86903/Main.java @@ -0,0 +1,6 @@ + +public class Main { + public static void main(String []argv) { + new Service().setContext("foo"); + } +} diff --git a/tests/bugs150/pr86903/Service.java b/tests/bugs150/pr86903/Service.java new file mode 100644 index 000000000..635172bd5 --- /dev/null +++ b/tests/bugs150/pr86903/Service.java @@ -0,0 +1,8 @@ + +public class Service implements GenericService { + String srvContext = "none"; + + public void setContext(String localCtx) { + this.srvContext=localCtx; + } +} diff --git a/weaver/src/org/aspectj/weaver/IntMap.java b/weaver/src/org/aspectj/weaver/IntMap.java index e5ab6bfd4..e61cbf4b4 100644 --- a/weaver/src/org/aspectj/weaver/IntMap.java +++ b/weaver/src/org/aspectj/weaver/IntMap.java @@ -37,12 +37,9 @@ public class IntMap { } - public ResolvedPointcutDefinition peekEnclosingDefinitition() { - try { - return (ResolvedPointcutDefinition)enclosingDefinition.get(enclosingDefinition.size()-1); - } catch (IndexOutOfBoundsException e) { - return null; - } + public ResolvedPointcutDefinition peekEnclosingDefinition() { + if (enclosingDefinition.size()==0) return null; + return (ResolvedPointcutDefinition)enclosingDefinition.get(enclosingDefinition.size()-1); } diff --git a/weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java b/weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java index 1c7af01c7..9934b7237 100644 --- a/weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java @@ -243,8 +243,22 @@ public class CflowPointcut extends Pointcut { if (!bindings.hasKey(freeVar)) continue; int formalIndex = bindings.get(freeVar); - ResolvedType formalType = - bindings.getAdviceSignature().getParameterTypes()[formalIndex].resolve(world); + + // We need to look in the right place for the type of the formal. Suppose the advice looks like this: + // before(String s): somePointcut(*,s) + // where the first argument in somePointcut is of type Number + // for free variable 0 we want to ask the pointcut for the type of its first argument, if we only + // ask the advice for the type of its first argument then we'll get the wrong type (pr86903) + + ResolvedPointcutDefinition enclosingDef = bindings.peekEnclosingDefinition(); + ResolvedType formalType = null; + + // Is there a useful enclosing pointcut? + if (enclosingDef!=null && enclosingDef.getParameterTypes().length>0) { + formalType = enclosingDef.getParameterTypes()[freeVar].resolve(world); + } else { + formalType = bindings.getAdviceSignature().getParameterTypes()[formalIndex].resolve(world); + } ConcreteCflowPointcut.Slot slot = new ConcreteCflowPointcut.Slot(formalIndex, formalType, i); diff --git a/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java b/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java index 3afb4350e..25fa8edcb 100644 --- a/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java +++ b/weaver/src/org/aspectj/weaver/patterns/IfPointcut.java @@ -263,7 +263,7 @@ public class IfPointcut extends Pointcut { final IfPointcut ret; if (extraParameterFlags < 0 && testMethod == null) { // @AJ style, we need to find the testMethod in the aspect defining the "if()" enclosing pointcut - ResolvedPointcutDefinition def = bindings.peekEnclosingDefinitition(); + ResolvedPointcutDefinition def = bindings.peekEnclosingDefinition(); if (def != null) { ResolvedType aspect = inAspect.getWorld().resolve(def.getDeclaringType()); for (Iterator memberIter = aspect.getMethods(); memberIter.hasNext();) { @@ -327,7 +327,7 @@ public class IfPointcut extends Pointcut { } ret.residueSource = advice.getPointcut().concretize(inAspect, inAspect, ret.baseArgsCount, advice); } else { - ResolvedPointcutDefinition def = bindings.peekEnclosingDefinitition(); + ResolvedPointcutDefinition def = bindings.peekEnclosingDefinition(); if (def == CflowPointcut.CFLOW_MARKER) { inAspect.getWorld().showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.IF_LEXICALLY_IN_CFLOW), -- 2.39.5