Skip to content

Fuzzer generates values when class is private and extends Collection #1660

Closed
@tyuldashev

Description

@tyuldashev

Description
Even though #1635 is fixed, still when private class extends Collection then Fuzzer generates test with usage of reflection.

To Reproduce

Steps to reproduce the behavior:

import java.util.ArrayList;


public class PrivateTest {
    public void foo(Call call) {
        
    }

    private static class Call extends ArrayList {
        public Call() {
        }
    }
}
  1. Set Fuzzer to to 100%
  2. Generate test for code above

Expected behavior

No tests are generated

Actual behavior

Fuzzer generates test:

    ///region FUZZER: SUCCESSFUL EXECUTIONS for method foo(com.google.common.primitives.PrivateTest.Call)

    /**
     * @utbot.classUnderTest {@link PrivateTest}
     * @utbot.methodUnderTest {@link PrivateTest#foo(PrivateTest.Call)}
     */
    @Test
    public void testFoo1() throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        PrivateTest privateTest = new PrivateTest();
        Class callClazz = Class.forName("com.google.common.primitives.PrivateTest$Call");
        Constructor callConstructor = callClazz.getDeclaredConstructor();
        callConstructor.setAccessible(true);
        Object[] callConstructorArguments = new Object[0];
        Object call = callConstructor.newInstance(callConstructorArguments);

        Class privateTestClazz = Class.forName("com.google.common.primitives.PrivateTest");
        Method fooMethod = privateTestClazz.getDeclaredMethod("foo", callClazz);
        fooMethod.setAccessible(true);
        Object[] fooMethodArguments = new Object[1];
        fooMethodArguments[0] = call;
        fooMethod.invoke(privateTest, fooMethodArguments);
    }

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