Menu

#21 Nested event announcement replaces announce statement bodies

1.2
open
9
2012-04-27
2011-12-13
Robert Dyer
No

When an event is announced in a recursive fashion, the *last* announce statement's body becomes the body for *all* event chains. This is due to using a single static variable to maintain body in the EventFrame. A test case follows.

public void event E { }

public class C {
public static void main(String[] args) {
new H();
new C().m();
}
public void m() {
announce E(){
System.out.println("first");
}
}
}

public class H {
public H() {
register(this);
}
static boolean again = true;
public void handler(E next) throws Throwable {
if (again) {
again = false;
announce E(){
System.out.println("second");
}
}
next.invoke();
System.out.println("handler");
}
when E do handler;
}

Expected output:
second
handler
first
handler

Observed output:
second
handler
second
handler

Discussion

  • Robert Dyer

    Robert Dyer - 2011-12-13

    E.java

     
  • Robert Dyer

    Robert Dyer - 2011-12-13

    C.java

     
  • Robert Dyer

    Robert Dyer - 2011-12-13

    H.java

     
  • Hridesh Rajan

    Hridesh Rajan - 2012-04-27
    • priority: 7 --> 9
    • assigned_to: nobody --> robdyer