Skip to content

Ambiguous method call with null when Object has two suitable constructors #1056

Open
@alisevych

Description

@alisevych

Description

BaseStreamExample$CustomCollection.toArray() is being tried to call with null argument.
Though thee are 2 overloaded methods with different argument types.

To Reproduce

  1. Run the 'UTBotJava' project in IntelliJ Idea 2022.1.4
  2. Install one of the latest from main branch
  3. Open test generation dialog for utbot-sample/src/main/java/org/utbot/examples/stream/BaseStreamExample.java
  4. Select CustomCollection class
  5. click Generate Tests
  6. wait tests to be generated

Expected behavior

Generated tests should be compiled.

Actual behavior

There is a test method with Ambiguous method call CE

Visual proofs

    @Test
    public void testToArray3() {
        Object[] objectArray = {null, null, null, null, null, null, null, null, null};
        CustomCollection customCollection = new CustomCollection(objectArray);
        
        /* This test fails because method [generics.CustomCollection.toArray] produces [java.lang.NullPointerException]
            java.base/java.util.Arrays$ArrayList.toArray(Arrays.java:4340)
            generics.CustomCollection.toArray(CustomCollection.java:54) */
        customCollection.toArray(null);
    }

CE occurs in CustomCollection.toArray(null).

This happens, because we have two methods: CustomCollection::toArray(Object[]) and Collection::toArray(IntFunction) defined in super interface of CustomCollection.

Originally posted by @sergeypospelov in #1043 (comment)

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorctg-bugIssue is a bug

Type

No type

Projects

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions