Skip to content

JSpecify: @NullMarked scope not detected for constructor/setter parameters #4079

Description

@RaniAgus

Expected behavior

When a target class is annotated @NullMarked, unannotated constructor parameters should be treated as @NonNull. Mapping a @Nullable source to such a parameter without a default value should produce a compile error.

Given:

@NullMarked
public class Target {
    private final Nested nested;
    public Target(Nested nested) { this.nested = nested; } // implicitly @NonNull
}

@NullMarked
public class Source {
    private final @Nullable Nested nested;
    public @Nullable Nested getNested() { return nested; }
}

@Mapper
@NullMarked
public interface Issue4079Mapper {
    Target map(Source source);
}

Expected: compilation fails with

error: Can't map potentially nullable source property "nested" to @NonNull constructor parameter "nested".

Actual behavior

Compilation succeeds.

Steps to reproduce the problem

Can be reproduced in this branch: main...RaniAgus:mapstruct:issues/4079

MapStruct Version

1.7.0.Beta2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions