NullPointerException caused by empty collection attribute in incremental flushing

Issue #303 resolved
Jesper Öqvist created an issue

The following test case gives a NullPointerException due to bugs in the incremental attribute flushing:

A ::= B* C*;
B ::= <NAME>;
C ::= <NAME> <TO:Integer>;
aspect Test {
  inh A C.a();
  eq A.getChild().a() = this;

  coll HashSet<C> B.cs() root A;

  C contributes this
      to B.cs()
      for a().getB(getTO());
}
public class Test {
  public static void main(String[] args) {
    int N = 6;
    A a = new A();
    for (int i = 0; i < N; ++i) {
      a.addB(new B("b"+i));
    }

    a.addC(new C("c1", 1));
    a.addC(new C("c2", 2));
    a.addC(new C("c3", 3));
    a.addC(new C("c4", 5));

    checkCollections(a, "before", 0, 1, 1, 1, 0, 1);

    // Transform:
    a.getBList().removeChild(2);

    checkCollections(a, "after", 0, 1, 1, 0, 1);
  }

  static void checkCollections(A a, String phase, int... sizes) {
    for (int i = 0; i < sizes.length; ++i) {
      testEqual(phase + "@" + a.getB(i).getNAME(), sizes[i], a.getB(i).cs().size());
    }
  }

  static void testEqual(String msg, int a, int b) {
    if (a != b) {
      System.out.format("Error %s : %d != %d%n", msg, a, b);
    }
  }
}

Error output:

Exception in thread "main" java.lang.NullPointerException
    at ast.B.reactToDependencyChange(B.java:196)
    at ast.ASTNode$DepGraphNode.dependencyChanged(ASTNode$DepGraphNode.java:164)
    at ast.ASTNode$DepGraphNode.notifyDependencies(ASTNode$DepGraphNode.java:150)
    at ast.ASTNode.removeChild(ASTNode.java:312)
    at ast.List.removeChild(List.java:72)
    at Test.main(Test.java:26)

The dependency tracking for collection attributes is incorrect right now and should be fixed. It is easy to fix the NPE but that alone will not fix the incremental update of collection attributes.

Comments (2)

  1. Jesper Öqvist reporter

    Fix errors in incremental collection attributes

    Improve dependency tracking and flushing for incremental collection attributes by treating the survey phase as an attribute with its own dependency graph node. This makes all collection attribute instances depend on the survey phase and any change which flushes the survey results leads to flushing all collection attribute instances as well.

    fixes #302 (bitbucket) fixes #303 (bitbucket)

    → <<cset 7938671b06a8>>

  2. Log in to comment