Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Java fuzzer can't create any values for types with no public constructor (e.g. LocalDateTime) #2437

Open
Labels
comp-fuzzingIssue is related to the fuzzing ctg-bugIssue is a bug lang-javaIssue is related to Java support
@IlyaMuravjov

Description

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    comp-fuzzingIssue is related to the fuzzing ctg-bugIssue is a bug lang-javaIssue is related to Java support

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /