Skip to content

Generated code not compatible with JSpecify annotations #1588

Open
@asoftwareguy

Description

@asoftwareguy

Issue Description

Generated sources are not compatible with JSpecify annotations. org.jspecify.annotations.NonNull is specified as @Target(TYPE_USE) so the annotation needs to directly precede the type.

Steps to Reproduce

  1. Install plugin
  2. Set up project to use the config below
  3. Create a simple schema with a required element on a list type
type Example {

    listExample: [String]!
}
  1. Run a build to attempt to compile
  2. Compilation error:
    /build/generated/sources/graphqlCodegen/test/graphql/model/Example.java:NN: error: scoping construct cannot be annotated with type-use annotation: @org.jspecify.annotations.NonNull
    private java.util.List listExample;
    ^

Expected Result

The sources are generated and can compile without errors.

private java.util. @org.jspecify.annotations.NonNull List<String> listExample;

Actual Result

The sources are generated in a way that cannot be compiled.

    @org.jspecify.annotations.NonNull
    private java.util.List<String> listExample;

Your Environment and Setup

  • graphql-java-codegen version: 5.10.0
  • Build tool: Gradle 8.13
  • Mapping Config:
graphqlCodegen {
    graphqlSchemas {
        rootDir = "$projectDir/src/main/resources/graphql"
    }
    generateApis = false
    generateEqualsAndHashCode = true
    generateImmutableModels = true
    generateToString = true
    modelValidationAnnotation = '@org.jspecify.annotations.NonNull'
    outputDir = new File(graphqlCodegenSourcesDir)
    packageName = 'test.graphql.model'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions