Skip to content

Bad test is produced when use concrete classes for implementing interface with generic #2450

Description

@Markoutte

Description

When there're only one implementation of some interface with generic type fuzzing choose this implementation even it is not suitable for a method.

To Reproduce

  1. Use only fuzzer
  2. Generate test for method test.
publicclassImplementations {
publicinterfaceA<T> {
TgetValue();
}
publicstaticclassAImplimplementsA<String> {
privatefinalStringvalue;
publicAImpl(Stringvalue) {
this.value = value;
}
@OverridepublicStringgetValue() {
returnvalue;
}
}
publicstaticinttest(A<Integer> value) {
if (value.getValue() < 0) {
return0;
}
returnvalue.getValue();
}
}

Expected behavior

The only one method with null is generated, because there're no other options to create this class by fuzzer.

Actual behavior

2 tests are generated: with null and other with AImpl:

@Test@DisplayName("test: arg_0 = AImpl(String) -> throw ClassCastException")
publicvoidtestTestThrowsCCE() {
AImplaImpl = newAImpl("-3E");
/* This test fails because method [sanity.Implementations.test] produces [java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer] sanity.Implementations.test(Implementations.java:24) */Implementations.test(aImpl);
}

This test cannot be compiled.

Additional context

The issue was introduced by 19fc16c

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