Skip to content

Commit

Permalink
Never pop elements from Stack<AroundClosure>
Browse files Browse the repository at this point in the history
Otherwise, we would jeopardise asynchronous proceeding, see
eclipse-aspectj#129 (comment)

Instead, we
  - keep the stack,
  - but treat it like a list (Stack implements the List interface),
  - keeping a current closure index,
  - using 'get(currentArcIndex)' instead of `peek()` and `pop()`.

Fixes eclipse-aspectj#128.

Signed-off-by: Alexander Kriegisch <[email protected]>
  • Loading branch information
kriegaex committed Feb 26, 2022
1 parent a3e3680 commit 1584914
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,44 +140,44 @@ public final String toLongString() {
// will either be using arc or arcs but not both. arcs being non-null
// indicates it is in use (even if an empty stack)
private AroundClosure arc = null;
private Stack<AroundClosure> arcs = null;
private final Stack<AroundClosure> arcs = new Stack<>();
private int currentArcIndex = -1;

public void set$AroundClosure(AroundClosure arc) {
this.arc = arc;
}

public synchronized void stack$AroundClosure(AroundClosure arc) {
// If input parameter arc is null this is the 'unlink' call from AroundClosure
if (arcs == null) {
arcs = new Stack<>();
}
if (arc==null) {
this.arcs.pop();
} else {
if (arc != null) {
this.arcs.push(arc);
currentArcIndex++;
}
}
}

public synchronized Object proceed() throws Throwable {
// when called from a before advice, but be a no-op
if (arcs == null) {
if (currentArcIndex < 0) {
if (arc == null) {
return null;
} else {
return arc.run(arc.getState());
}
} else {
return arcs.peek().run(arcs.peek().getState());
final AroundClosure ac = arcs.get(currentArcIndex--);
final Object result = ac.run(ac.getState());
currentArcIndex++;
return result;
}
}

public synchronized Object proceed(Object[] adviceBindings) throws Throwable {
// when called from a before advice, but be a no-op
AroundClosure ac = null;
if (arcs == null) {
if (currentArcIndex < 0) {
ac = arc;
} else {
ac = arcs.peek();
ac = arcs.get(currentArcIndex);
}

if (ac == null) {
Expand Down Expand Up @@ -254,7 +254,10 @@ public synchronized Object proceed(Object[] adviceBindings) throws Throwable {
// state[i] = adviceBindings[formalIndex];
// }
// }
return ac.run(state);
currentArcIndex--;
final Object result = ac.run(state);
currentArcIndex++;
return result;
}
}

Expand Down

0 comments on commit 1584914

Please sign in to comment.