Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

JSpecify: Missing compile error when reused method returns `@Nullable` to `@NonNull` constructor

Đang mở
#4,081 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

@hduelme đang làm issue này rồi.

Từ ngày 9/8/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

bug JSpecify
Expected behavior

Missing compile error when reused method returns @Nullable but constructor expects @NonNull parameter

Given:

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

    default Target.@Nullable Payload mapPayload(String payload) {
        if ( payload.isBlank() ) {
            return null;
        }
        return new Target.Payload( payload );
    }
}

public class Source {
    private final String payload;

    public @NonNull String getPayload() { return this.payload; }
}

public class Target {
    private final Payload payload;
    public Target(@NonNull Payload payload) { this.payload = payload; }

    public class Payload {
        private final String value;
        public Payload(@NonNull String value) { this.value = value; }
    }
}

Expected: compilation fails with

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

Compilation succeeds silently:

@Generated
public class ErroneousIssue4081MapperImpl implements ErroneousIssue4081Mapper {

    @Override
    public Target map(Source source) {

        Target.Payload payload = null;

        payload = mapValue( source.getPayload() );

        Target target = new Target( payload );

        return target;
    }
}
Steps to reproduce the problem

A @NullMarked mapper where a reused method has an explicit @Nullable return type, and the target constructor parameter is @NonNull.

Can be reproduced in this branch: https://github.com/mapstruct/mapstruct/compare/main...RaniAgus:mapstruct:issues/4081

MapStruct Version

1.7.0.Beta2

Ngôn ngữ chính
Java
Star
7.7k
Fork
1.1k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của mapstruct/mapstruct

Tất cả issue của mapstruct/mapstruct

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.