External annotations: Not annotated parameter overrides @NotNull parameter

已回答

I have implemented method and added external annotation

But I still get warning "Not annotated parameter overrides @NotNull parameter"

 

Is it bug?

1

Hi, does it help if you invalidate caches? (File | Invalidate cache)? 

0
Avatar
Permanently deleted user

Unfortunately not. :(

0

Could you please provide a project example?

0
Avatar
Permanently deleted user

I cannot reproduce it in trivial example. Otherwise I would file bug.

0
Avatar
Permanently deleted user

I see it during commit. Not during "Build Project"

0

Is there any possibility to remove sensitive data from a project where the problem reproduce?

0
Avatar
Permanently deleted user

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."

2

>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.

0
Avatar
Permanently deleted user

>I have implemented method and added external annotation

0

@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.

0
Avatar
Permanently deleted user

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:

package GeoffButler.Test;
public class Thing implements Comparable<Thing>
{
@Override public int compareTo( Thing that )
{
return 0;
}
}
1
Avatar
Permanently deleted user

@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".

1

>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.

0
Avatar
Permanently deleted user

Can confirm with the below the issue is still present

0

When I annotate the parameter as @Nonnull the warning goes away:

 

as expected. What is your case?

0
Avatar
Permanently deleted user

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.

1
Avatar
Permanently deleted user

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.

1

>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.

0

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.

0

Hello, please create an issue with the code sample attached to reproduce the case:

https://youtrack.jetbrains.com/issues/IDEA

Thank you 

0

Make sure you're using the correct `NotNull` type. For example, the following gives the warning:

import com.sun.istack.internal.NotNull;

public class MyClass implements Comparable<MyClass> {

  @Override
  public int compareTo(@NotNull MyClass o) {
    return 0;
  }
}

whereas the correct type does not!

import org.jetbrains.annotations.NotNull;

public class MyClass implements Comparable<MyClass> {

  @Override
  public int compareTo(@NotNull MyClass o) {
    return 0;
  }
}

See the JetBrains Java Annotations package

0

请先登录再写评论。