Skip to content

Use constructor call for package-private class #346

Closed
@alisevych

Description

@alisevych

Description

If analyzed class has package-private (default) access - and there is a public or a package-private constructor - need to use the applicable constructor. Currently reflection is used and createInstance (String className) is generated.

To Reproduce

Preconditions:

  1. Open/create a project in IntelliJ Idea
  2. UTBotJava plugin is installed

Steps to reproduce the behavior:

  1. Add the following java class:
 class A {

    public int a = 0;
    public int b = 7;

    public A() {
    }

    A(int a, int b) {
        this.a = a;
        this.b = b;
    }

    int sum() {
        return a + b;
    }
}
  1. Generate Test with UTBot for this class
  2. Open the generated test

Expected behavior

Constructor call must be used to instantiate A object.

        A a = new A(-255, -255);

Actual behavior

There is createInstance(String className) method generated.
It is used to instantiate A object in the test.

        A a = ((A) createInstance("A"));
        a.b = -255;
        a.a = -255;

Environment

IDEA 2022.1.3
JDK 8
UTBotJava plugin build

Metadata

Metadata

Assignees

Labels

comp-symbolic-engineIssue is related to the symbolic execution enginectg-bugIssue is a bugpriority-top-focusTop priority chosen by dev team

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions