Skip to content

DataFetcherResult.newResult<T>() type parameter missing @Nullable bound for Kotlin JSpecify interop #4364

@mrmegapolys

Description

@mrmegapolys

Describe the bug

DataFetcherResult<T extends @Nullable Object> and Builder<T extends @Nullable Object> correctly allow nullable T. However, the no-arg factory method still declares <T> without the @Nullable bound:

public static <T> Builder<T> newResult() {
    return new Builder<>();
}

Under @NullMarked, Kotlin 2.1+ infers T : Any, making DataFetcherResult.newResult<MyType?>() a compile error.

This is the same class of issue as #4179 (getDataLoader type bounds, fixed in #4180), but for DataFetcherResult.

To Reproduce

// graphql-java 25.0, Kotlin 2.3+
// Compile error: Type argument is not within its bounds: must be subtype of 'Any'
val result = DataFetcherResult.newResult<String?>()
    .data(null)
    .build()

Expected behavior

The above should compile. Fix:

- public static <T> Builder<T> newResult()
+ public static <T extends @Nullable Object> Builder<T> newResult()

Note: A fix already exists on branch claude/kotlin-jspecify-e2e-test-rdaLf (commit f8f06a25, Mar 8 2026) but has no associated PR.

Versions: graphql-java 25.0, Kotlin 2.3.20

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions