Skip to content

All equals methods with jspecify support must have a Nullable argument #18929

@therepanic

Description

@therepanic

All module classes that support jspecify (and will support it in the future) must have @Nullable in their equals method.

I believe this is necessary for several reasons. The main one is that the Object.equals contract itself can always accept null, and we're removing this. This leads to bugs like #18927. For example, in this specific issue, the Kotlin compiler can't correctly resolve the equals signature.

Examples are readily available. In Spring projects, this has already been implemented at the very beginning of jspecify implementation. For example:

Spring Framework:
https://github.com/spring-projects/spring-framework/blob/main/spring-core/src/main/java/org/springframework/util/comparator/BooleanComparator.java#L74
https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/main/java/org/springframework/http/HttpHeaders.java#L2066

Spring grpc
https://github.com/spring-projects/spring-grpc/blob/main/spring-grpc-test-spring-boot-autoconfigure/src/main/java/org/springframework/boot/grpc/test/autoconfigure/InProcessTransportContextCustomizerFactory.java#L73

We should fix this and take this into account in the future when adding jspecify support to other modules.

Relates: #18927

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions