Skip to content

Incorrect reflection call leads to compilation errors #1024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
EgorkaKulikov opened this issue Sep 28, 2022 · 1 comment
Closed

Incorrect reflection call leads to compilation errors #1024

EgorkaKulikov opened this issue Sep 28, 2022 · 1 comment
Assignees
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug spec-release-tailings Failed to include in the current release, let's include it in the next one

Comments

@EgorkaKulikov
Copy link
Collaborator

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
@volivan239
Copy link
Collaborator

Fixed by #1029

Repository owner moved this from Todo to Done in UTBot Java Oct 4, 2022
@alisevych alisevych added this to the 2022.10.1 Release milestone Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug spec-release-tailings Failed to include in the current release, let's include it in the next one
Projects
Archived in project
Development

No branches or pull requests

3 participants