Skip to content

Incorrect reflection call leads to compilation errors #1024

Closed

Description

@EgorkaKulikov

Description

Try to generate tests for the following class, set timeout at least to 60s.

import org.antlr.runtime.tree.TreeVisitor;
import org.antlr.runtime.tree.TreeVisitorAction;
import org.antlr.v4.parse.GrammarASTAdaptor;
import org.antlr.v4.tool.ast.GrammarAST;

public class Grammarin {
    public void setGrammarPtr(final org.antlr.v4.tool.Grammar g, GrammarAST tree) {
        if (tree != null) {
            TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor());
            v.visit(tree, new TreeVisitorAction() {
                public Object pre(Object t) {
                    ((GrammarAST) t).g = g;
                    return t;
                }

                public Object post(Object t) {
                    return t;
                }
            });
        }
    }
}

The following code i generated:

    @Test
    @DisplayName("setGrammarPtr: -> tree != null : True")
    public void testSetGrammarPtr_TreeNotEqualsNull_2() throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
        Grammarin grammarin = new Grammarin();
        GrammarRootAST tree = new GrammarRootAST(null);
        tree.token = null;
        Class baseTreeClazz = Class.forName("org.antlr.runtime.tree.BaseTree");
        Field childrenField = baseTreeClazz.getDeclaredField("children");
        childrenField.setAccessible(true);
        childrenField.get(tree) = new ArrayList();

        grammarin.setGrammarPtr(null, tree);
    }

Line with getter leads to the compilation error

childrenField.get(tree) = new ArrayList(); - variable expected

Activity

  1. added
    spec-release-tailingsFailed to include in the current release, let's include it in the next one
    on Sep 29, 2022
  2. volivan239 commented on Oct 4, 2022

    @volivan239
    Collaborator

    Fixed by #1029

  3. Repository owner moved this from Todo to Done in UTBot Javaon Oct 4, 2022
  4. added this to the 2022.10.1 Release milestone on Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

comp-codegenIssue is related to code generatorctg-bugIssue is a bugspec-release-tailingsFailed to include in the current release, let's include it in the next one

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions