Skip to content

Unnecessary reflection usage by fuzzer for instantiating package-private classes #892

Closed
@volivan239

Description

@volivan239

Description

If we are generating tests for a method of package-private class, fuzzer will use reflection to instantiate it, even though it is not needed. Note that this only works for methods that have at least one argument.

To Reproduce

Launch plugin on the following class (not that it must be package-private):

class A {
    int f(int x) {
        return 0;
    }
}

Expected behavior

Instances of A in generated tests are produced via default constructor

Actual behavior

Instances are produced via reflection.

Visual proofs (screenshots, logs, images)

The following test is generated:

  @Test
  @DisplayName("f: x > 0 -> return 0")
  public void testFReturnsZero() throws Exception {
      A a = ((A) createInstance("arrays.A"));

      int actual = a.f(1);

      assertEquals(0, actual);
  }

Environment

Fuzzer should be enabled. Default amount of time for fuzzer is enough.

Metadata

Metadata

Assignees

Labels

comp-fuzzingIssue is related to the fuzzingctg-bugIssue is a bug

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions