External annotations: Not annotated parameter overrides @NotNull parameter
Answered
I have implemented method and added external annotation

But I still get warning "Not annotated parameter overrides @NotNull parameter"
Is it bug?
Please sign in to leave a comment.
Hi, does it help if you invalidate caches? (File | Invalidate cache)?
Unfortunately not. :(
Could you please provide a project example?
I cannot reproduce it in trivial example. Otherwise I would file bug.
I see it during commit. Not during "Build Project"
Is there any possibility to remove sensitive data from a project where the problem reproduce?
The bug is that this warning appears when "@NonNull" should be used to annotate an overridden parameter, but the warning text indicates that "@NotNull" is the missing parameter. Trivial reproduction includes implementing Comparable<YourClass> and not using the "@NonNull" annotation.
Buggy text: "Not annotated parameter overrides @NotNull parameter... This inspection reports problems related to @Nullable and @NotNull annotations usage configured in Constant conditions and exceptions inspection."
Instead should read something like "Not annotated parameter overrides @NonNull parameter... This inspection reports problems related to @Nullable, @NotNull, and @NonNull annotations usage configured in Constant conditions and exceptions inspection."
>The bug is that this warning appears when "@NonNull" should be used to annotate an overridden parameter, but the warning text indicates that "@NotNull" is the missing parameter. Trivial reproduction includes implementing Comparable<YourClass> and not using the "@NonNull" annotation.
This warning is expected behavior if you do not annotate the method parameter as NotNull/NonNull either in code or using external annotation.
Also make sure you have the NonNull annotation configured inFile | Settings | Editor | Inspections | Java | Probable bugs | @NotNull/@Nullable problems -> Configure annotations.
>I have implemented method and added external annotation
@Jozef Matejicka I understand that you did and this seems like a bug, but I can not reproduce it: it works for me (if annotate directory in Editor or via External annotation). If it is possible a sample project would be great to get to further investigate it. Thanks.
Thanks for the solution, it's been driving me crazy trying to find a way to remove the last warning from my code.
Here's my test case:
@Geoff Butler No problem :)
@Andrey Dernov, "This warning is expected behavior if you do not annotate the method parameter as NotNull/NonNull either in code or using external annotation."
That is not correct, I believe you're missing the nuance here (or maybe we are, see below). Annotating the method parameter as NotNull does not remove the warning. You must annotate the method parameter with NonNull. The problem is that the warning text directs the user to use NotNull. The two are not interchangeable.
"Also make sure you have the NonNull annotation configured inFile | Settings | Editor | Inspections | Java | Probable bugs | @NotNull/@Nullable problems -> Configure annotations."
Perhaps we do not quite understand what is needed here. Under Configure annotations are we supposed to repoint the arrow in the second box to javax.annotation.Nonnull? Are we supposed to click + and then search for "Nonnull (javax.annotation)"? It's not clear what you mean by "have the NonNull annotation configured".
>Are we supposed to click + and then search for "Nonnull (javax.annotation)"? It's not clear what you mean by "have the NonNull annotation configured".
Yes, you should have corresponding not null annotation (Nonnull) added to NotNull annotations. Same for nullable.
Can confirm with the below the issue is still present
When I annotate the parameter as @Nonnull the warning goes away:
as expected. What is your case?
There are comments in the thread such as "I cannot reproduce it in trivial example" and one from yourself "I understand that you did and this seems like a bug, but I can not reproduce it", hence the trivial test case. If you were talking about something else, sorry. I think it's reasonably obvious from my comment that I understand and accept the annotation as a fix. There is still a bug, though, in the text of the message.
Yes, the bug here is that the warning instructs you to do the wrong thing. Annotating with @Nonnull does indeed remove the warning. But the warning doesn't say to annotate with @Nonnull. It instructs you to annotate with @Notnull.
>But the warning doesn't say to annotate with @Nonnull. It instructs you to annotate with @Notnull.
There are multiply nullable / not null annotations that can be registered and all they can be used. You are very welcome to file a suggestion at https://youtrack.jetbrains.com/issues/IDEA to improve the text.
This is still an issue in
IntelliJ IDEA 2021.3.2 (Ultimate Edition)
Build #IU-213.6777.52, built on January 28, 2022
Not annotated parameter overrides @NotNull parameter
If i use @Nonnull the warning disappears.
Hello, please create an issue with the code sample attached to reproduce the case:
https://youtrack.jetbrains.com/issues/IDEA
Thank you
Make sure you're using the correct `NotNull` type. For example, the following gives the warning:
whereas the correct type does not!
See the JetBrains Java Annotations package