Skip to content

[BUG][JAVA][Spring] useJspecify: fluent setter override in an allOf child drops @Nullable from the parent's nullable property #25831

Backlog

Description

@BigMichi1

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

With useJspecify=true, the spring generator annotates a nullable property's fluent setter with @Nullable on the model that declares the property, but the fluent override it writes in a subclass (allOf child) has no @Nullable on the same parameter. The model package is @NullMarked, so the override declares the parameter non-null while the method it overrides accepts null. NullAway and other JSpecify checkers report the override, and callers holding a @Nullable String cannot call child.description(value) without a cast or an extra null check.

Actual (Child.java):

  public Child description(String description) {
    super.description(description);
    return this;
  }

Expected:

  public Child description(@Nullable String description) {
    super.description(description);
    return this;
  }

Base.java, generated in the same run, is correct:

  public Base description(@Nullable String description) {
    this.description = description;
    return this;
  }
openapi-generator version

7.27.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: repro
  version: 1.0.0
paths: {}
components:
  schemas:
    Base:
      type: object
      required: [kind]
      properties:
        kind:
          type: string
        description:
          type: string
          nullable: true
      discriminator:
        propertyName: kind
    Child:
      allOf:
        - $ref: '#/components/schemas/Base'
        - type: object
          properties:
            extra:
              type: string
Generation Details
openapi-generator-cli generate -i spec.yaml -g spring -o out \
  --additional-properties=useJspecify=true,openApiNullable=false,useSpringBoot3=true,interfaceOnly=true,useBeanValidation=true
Steps to reproduce

Reproducer repository: https://github.com/BigMichi1/openapi-generator-jspecify-override-repro

  1. Save the spec above as spec.yaml and run the command.
  2. Compare description(...) in out/src/main/java/org/openapitools/model/Base.java and Child.java; package-info.java carries @org.jspecify.annotations.NullMarked.
Related issues/PRs
Suggest a fix

In JavaSpring/pojo.mustache, the block that re-declares the parent's fluent setters for an allOf child (the one calling super.<name>(...)) could emit the same nullable annotation the parent's setter gets for that variable.

Activity

  1. shu-chen-dot-ca commented on Nov 27, 2026

    @shu-chen-dot-ca

    I'd like to work on this one and will open a PR shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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