Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java fuzzer ignores type parameters of field types #2430

Closed
IlyaMuravjov opened this issue Jul 20, 2023 · 0 comments · Fixed by #2431
Closed

Java fuzzer ignores type parameters of field types #2430

IlyaMuravjov opened this issue Jul 20, 2023 · 0 comments · Fixed by #2431
Assignees
Labels
comp-fuzzing Issue is related to the fuzzing ctg-bug Issue is a bug lang-java Issue is related to Java support

Comments

@IlyaMuravjov
Copy link
Collaborator

IlyaMuravjov commented Jul 20, 2023

Description

Java fuzzer ignores type parameters of fields (raw types are used), for example, in class below List is used instead of List<String>, causing fuzzer to generate lists of arbitrary Objects.

public class StringListHolder {
    private List<String> strings;

    public List<String> getStrings() {
        return strings;
    }

    public void setStrings(List<String> strings) {
        this.strings = strings;
    }

    public void methodUnderTest() {}
}

To Reproduce

Run the following unit test

@Test
fun `fuzzer correctly works with settable field that has a parameterized type`() {
    val seenStringListHolders = mutableListOf<StringListHolder>()
    var remainingRuns = 100
    runBlockingWithContext {
        runJavaFuzzing(
            TestIdentityPreservingIdGenerator,
            methodUnderTest = StringListHolder::methodUnderTest.javaMethod!!.executableId,
            constants = emptyList(),
            names = emptyList(),
        ) { thisInstance, _, _ ->
            thisInstance?.let {
                seenStringListHolders.add(
                    ValueConstructor().construct(listOf(it.model)).single().value as StringListHolder
                )
            }
            remainingRuns--
            BaseFeedback(Trie.emptyNode(), if (remainingRuns > 0) Control.CONTINUE else Control.STOP)
        }
    }
    val seenStrings = seenStringListHolders.flatMap { it.strings.orEmpty().filterNotNull() }
    assertNotEquals(emptyList<String>(), seenStrings)
    seenStrings.forEach { assertInstanceOf(String::class.java, it) }
}

Expected behavior

Test passes.

Actual behavior

Test fails.

Visual proofs (screenshots, logs, images)

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')
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')
	at org.utbot.fuzzing.JavaFuzzingTest.fuzzer correctly works with settable field that has a parameterized type(JavaFuzzingTest.kt:412)
@IlyaMuravjov IlyaMuravjov added ctg-bug Issue is a bug comp-fuzzing Issue is related to the fuzzing lang-java Issue is related to Java support labels Jul 20, 2023
@IlyaMuravjov IlyaMuravjov self-assigned this Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-fuzzing Issue is related to the fuzzing ctg-bug Issue is a bug lang-java Issue is related to Java support
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant