Collection attribute runtime debug check does not work

Issue #238 resolved
Jesper Öqvist created an issue

JastAdd 2.1.13

Collection attributes have a runtime debug check to test whether the attribute is evaluated in a node not connected to a collection root node when using the --debug flag. This debug check is incorrect. The generated code looks like this:

private Collection<B> set_compute() {
    ASTNode node = this;
    while(node.getParent() != null && !(node instanceof Root)) {
        node = node.getParent();
    if (node == null) {
        throw new RuntimeException("Trying to evaluate collection attribute in subtree not attached to main tree");
    Root root = (Root) node;

This check will never fail because the node.getParent() != null test in the loop prevents node from becoming null. Instead a ClassCastException is thrown by the next statement after the if block.

We should add regression tests for this runtime check and fix it.

Comments (3)

  1. Log in to comment