Skip to content

Fuzzer ignores generics of class StringMap extends HashMap<String, String> #2571

Open
@IlyaMuravjov

Description

@IlyaMuravjov

Description

Fuzzer tries to put arbitrary Objects into StringMap

To Reproduce

  • Set fuzzing to 100%
  • Generate tests for the following class
public class StringMap extends HashMap<String, String> {
    public String getAnyString() {
        return keySet().iterator().next();
    }
}

Expected behavior

There's one passing and one failing test.

Actual behavior

No passing tests are generated, one of the tests fails to compile with the following error: "incompatible types: Object cannot be converted to String stringMap.put(object, object1);".

Visual proofs (screenshots, logs, images)

/**
 * @utbot.classUnderTest {@link StringMap}
 * @utbot.methodUnderTest {@link StringMap#getAnyString()}
 */
@Test
@DisplayName("getAnyString:  -> throw ClassCastException")
public void testGetAnyStringThrowsCCE() {
    StringMap stringMap = new StringMap();
    Object object = new Object();
    Object object1 = new Object();
    stringMap.put(object, object1);
    
    /* This test fails because method [org.example.StringMap.getAnyString] produces [java.lang.ClassCastException: class java.lang.Object cannot be cast to class java.lang.String (java.lang.Object and java.lang.String are in module java.base of loader 'bootstrap')]
        org.example.StringMap.getAnyString(StringMap.java:7) */
    stringMap.getAnyString();
}

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorcomp-fuzzingIssue is related to the fuzzingctg-bugIssue is a buglang-javaIssue is related to Java support

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions