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 can't create any values for types with no public constructor (e.g. LocalDateTime) #2437

Open
IlyaMuravjov opened this issue Jul 24, 2023 · 1 comment · May be fixed by #2440
Open
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 24, 2023

Description

When creating instances of arbitrary classes Java fuzzer only considers their accessible constructors. However, some classes (e.g. LocalDateTime) only have private constructors while their instances are meant to be created using static methods.

Real world (concrete) example

Same as in #2428

To Reproduce

Run the following unit test.

@Test
fun `fuzzer can create instances of classes without public constructors but with static factory method in their class`() {
    var seenLocalDateTime = false
    runBlockingWithContext {
        runJavaFuzzing(
            TestIdentityPreservingIdGenerator,
            methodUnderTest = LocalDateTime::getMinute.javaMethod!!.executableId,
            constants = emptyList(),
            names = emptyList(),
        ) { thisInstance, _, _ ->
            val control = runCatching {
                ValueConstructor()
                    .construct(listOfNotNull(thisInstance?.model))
                    .singleOrNull()?.value
            }.getOrNull()?.let { constructedThisInstance ->
                assertInstanceOf(LocalDateTime::class.java, constructedThisInstance)
                seenLocalDateTime = true
                Control.STOP
            } ?: Control.CONTINUE
            BaseFeedback(Trie.emptyNode(), control)
        }
    }
    assertTrue(seenLocalDateTime) { "No value was generated for type LocalDateTime" }
}

Expected behavior

Test passes.

Actual behavior

Test fails.

Visual proofs (screenshots, logs, images)

No value was generated for type LocalDateTime ==> expected: <true> but was: <false>
@alisevych
Copy link
Member

@IlyaMuravjov
Could you please explain expected and actual behavior more in detail?
Here it is expected to use LocalDateTime static methods to instantiate it.

@IlyaMuravjov IlyaMuravjov linked a pull request Jul 24, 2023 that will close this issue
6 tasks
@alisevych alisevych removed their assignment Sep 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
Status: Todo
Development

Successfully merging a pull request may close this issue.

2 participants