From 26a4654ba4ebd7746b39fdf5d8f9122ea8246d61 Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 30 Oct 2006 10:26:22 +0000 Subject: [PATCH] fix for 162657 - remove the matchesNothingPointcut which has no source context (can cause npe when reporting messages) --- .../weaver/patterns/PointcutRewriter.java | 44 +++++++++++++++---- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/weaver/src/org/aspectj/weaver/patterns/PointcutRewriter.java b/weaver/src/org/aspectj/weaver/patterns/PointcutRewriter.java index f43158048..b5ce1cf51 100644 --- a/weaver/src/org/aspectj/weaver/patterns/PointcutRewriter.java +++ b/weaver/src/org/aspectj/weaver/patterns/PointcutRewriter.java @@ -35,25 +35,51 @@ public class PointcutRewriter { * See pr113257 */ public Pointcut rewrite(Pointcut pc,boolean forceRewrite) { - Pointcut result = pc; + Pointcut result = pc;//checkPC(result); if (forceRewrite || !isDNF(pc)) { if (WATCH_PROGRESS) System.out.println("Initial pointcut is ==> " + format(pc)); - result = distributeNot(result); + result = distributeNot(result);//checkPC(result); if (WATCH_PROGRESS) System.out.println("Distributing NOT gives ==> " + format(result)); - result = pullUpDisjunctions(result); + result = pullUpDisjunctions(result);//checkPC(result); if (WATCH_PROGRESS) System.out.println("Pull up disjunctions gives ==> " + format(result)); } else { if (WATCH_PROGRESS) System.out.println("Not distributing NOTs or pulling up disjunctions, already DNF ==> "+format(pc)); } - result = simplifyAnds(result); + result = simplifyAnds(result); // checkPC(result); if (WATCH_PROGRESS) System.out.println("Simplifying ANDs gives ==> " + format(result)); - result = sortOrs(result); + result = removeNothings(result);// checkPC(result); + if (WATCH_PROGRESS) System.out.println("Removing nothings gives ==> " + format(result)); + result = sortOrs(result);// checkPC(result); if (WATCH_PROGRESS) System.out.println("Sorting ORs gives ==> " + format(result)); - //result = removeNothings(result); - //if (WATCH_PROGRESS) System.out.println("Removing nothings gives ==> " + format(result)); return result; } + /** + * Checks pointcuts - used for debugging. + * - this variant checks if the context has been lost, since + * that can indicate an NPE will happen later reporting a message (pr162657). + * Not finished, but helped locate the problem ;) + */ + private void checkPC(Pointcut pc) { + if (isNot(pc)) { + NotPointcut npc = (NotPointcut)pc; + checkPC(npc.getNegatedPointcut()); + if (npc.getSourceContext()==null) throw new RuntimeException("Lost context"); + } else if (isOr(pc)) { + OrPointcut opc = (OrPointcut)pc; + checkPC(opc.getLeft()); + checkPC(opc.getRight()); + if (opc.getSourceContext()==null) throw new RuntimeException("Lost context"); + } else if (isAnd(pc)) { + AndPointcut apc = (AndPointcut)pc; + checkPC(apc.getLeft()); + checkPC(apc.getRight()); + if (apc.getSourceContext()==null) throw new RuntimeException("Lost context"); + } else { + if (pc.getSourceContext()==null) throw new RuntimeException("Lost context"); + } + } + public Pointcut rewrite(Pointcut pc) { return rewrite(pc,false); } @@ -147,7 +173,7 @@ public class PointcutRewriter { private Pointcut pullUpDisjunctions(Pointcut pc) { if (isNot(pc)) { NotPointcut npc = (NotPointcut)pc; - return new NotPointcut(pullUpDisjunctions(npc.getNegatedPointcut())); + return new NotPointcut(pullUpDisjunctions(npc.getNegatedPointcut())); } else if (isAnd(pc)) { AndPointcut apc = (AndPointcut) pc; // dive into left and right here... @@ -281,7 +307,7 @@ public class PointcutRewriter { // !!X => X return simplifyAnds(((NotPointcut)notBody).getNegatedPointcut()); } else { - return new NotPointcut(simplifyAnds(npc.getNegatedPointcut())); + return new NotPointcut(simplifyAnds(npc.getNegatedPointcut())); } } else if (isOr(pc)) { OrPointcut opc = (OrPointcut) pc; -- 2.39.5