Skip to content

When nullableAnnotationClass is set, argument to equals() should be annotated #268

@xzel23

Description

@xzel23

I use JSpecify annotations and @NullMarked at module level. That means all parameters not explicitly marked as @Nullable (or for example defined in a @NullUnmarked class) are non-nullable by default.

I use @RecordBuilder.Options(nullableAnnotationClass = "org.jspecify.annotations.Nullable") on a record class like this:

@RecordBuilder
@JsonIgnoreProperties(ignoreUnknown = true)
@RecordBuilder.Options(nullableAnnotationClass = "org.jspecify.annotations.Nullable")
public record ComparisonConfiguration(
        @Nullable Path pathA,
        @Nullable Path pathB,
        @Nullable Path pathOutput,
        @Nullable String filenameReport,
        @Nullable String patternFilename,
        boolean updateInBackground,
        boolean writeReport,
        boolean useRelativePathForFilesInOutputFolder,
        boolean extractSections,
        boolean trimLines,
        boolean ignoreWhitespace,
        boolean inlineDiffByWord,
        int contextLinesBefore,
        int contextLinesAfter,
        List<com.dua3.utility.text.FontDef> sectionFonts,
        List<Substitution> substitutions
) implements ComparisonConfigurationBuilder.With { ... }

RecorBuilder generates this code for equals():

    @Generated("io.soabase.recordbuilder.core.RecordBuilder")
    @Override
    public boolean equals(Object o) { ... }

But it should use the nullable annotation like this because equals() by contract must accept null and x.equals(null) == false for all x != null:

    @Generated("io.soabase.recordbuilder.core.RecordBuilder")
    @Override
    public boolean equals(org.jspecify.annotations.@Nullable Object o) { ... }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions