Skip to content

Null type safety not working with jakarta.validation.constraints.NotNull #3501

Open
eclipse-jdtls/eclipse.jdt.ls
#3067

Description

@thermcampos

[provide a description of the issue]

Environment
  • Operating System: Linux Ubuntu 22.04
  • JDK version: 17.0.8 (Oracle GraalVM 17.0.8+9.1 build 17.0.8+9-LTS-jvmci-23.0-b14)
  • Visual Studio Code version: 1.86.2
  • Java extension version: v1.28.1
Steps To Reproduce
  1. Create a method with org.springframework.lang.NonNull annotation
  2. Calls that method with arguments annotated with jakarta.validation.constraints.NotNull
  3. A yellow line shows up on the method call highlighting: Null type safety: The expression of type 'String' needs unchecked conversion to conform to '@NonNull String'Java(16778128)

[Please attach a sample project reproducing the error]
Here:
warnings-bug.zip

Please attach logs
Here:
warning-logs.log

Current Result

VS Code says it could be null, it may have null value.

Expected Result

No warnings at all, since it was annotated with NotNull;

Additional Informations

None

Activity

  1. changed the title [-]Null type safety not working with jakarta.vaidation.notNull[/-] [+]Null type safety not working with jakarta.validation.constraints.NotNull[/+] on Feb 16, 2024
  2. snjeza commented on Feb 19, 2024

    @snjeza
    Collaborator

    @RMCampos you can try to add

    org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=ignore
    

    to <your_project>/.settings/org.eclipse.jdt.core.prefs

    @fbricon @rgrunber We could set this property per default when null analysis is enabled.

  3. thermcampos commented on Feb 19, 2024

    @thermcampos
    Author

    @snjeza I have to projects inside the same root directory. Shall I put this on the root directory, or inside each project?

  4. snjeza commented on Feb 19, 2024

    @snjeza
    Collaborator

    @RMCampos You may want to take a look at Settings Global Preferences

  5. thermcampos commented on Feb 19, 2024

    @thermcampos
    Author

    @snjeza that worked! Thank you!

  6. reopened this on Feb 20, 2024
  7. self-assigned this
    on Feb 20, 2024
  8. added this to the Mid March 2024 milestone on Feb 20, 2024
  9. moved this to ✅ Done in IDE Cloudaptorson Feb 21, 2024
  10. agriffis commented on Jul 16, 2024

    @agriffis

    Hi @snjeza, I'm wondering if you could elaborate on the following statement:

    @fbricon @rgrunber We could set this property per default when null analysis is enabled.

    Why would jdtls set that property when null analysis is enabled? Does nullUncheckedConversion no longer apply in that case?

    Context: I'm using jdtls in a project with existing Eclipse settings, and trying to reconcile the changes that jdtls is making to those settings. See eclipse-jdtls/eclipse.jdt.ls#2655 (comment)

  11. snjeza commented on Jul 16, 2024

    @snjeza
    Collaborator

    Why would jdtls set that property when null analysis is enabled? Does nullUncheckedConversion no longer apply in that case?

    @agriffis We want to avoid

    1. A yellow line shows up on the method call highlighting: Null type safety: The expression of type 'String' needs unchecked conversion to conform to '@nonnull String'Java(16778128)

    See Steps To Reproduce

  12. agriffis commented on Jul 16, 2024

    @agriffis

    @snjeza Thanks, I understand. The part that isn't clear is whether there is a downside to nullUncheckedConversion=ignore, or if it is completely obviated by null analysis.

    Or another way to ask: Does the jdtls know that org.springframework.lang.NonNull and jakarta.validation.constraints.NotNull are both non-null annotations? Only the former appears in the jdtls sources. It seems that the latter is simply not recognized as a non-null annotation, and the provided zip-file doesn't contain any configuration to change this.

    In that case, disabling nullUncheckedConversion might not be the right answer.

  13. fbricon commented on Oct 17, 2025

    @fbricon
    Collaborator

    Reopening as automatically disabling nullUncheckedConversion is not a universal solution

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions