Disable @NotNull annotation when generating code

Answered

Hello,

Is there a way to disable insertion of @NotNull annotations when generating code such as overriding methods?

For example, in the code snippet below, I do not want the @NotNull annotation to be added to the MyFile constructor when using Generate / Override Methods... to generate this constructor.

import org.jetbrains.annotations.NotNull;

import java.io.File;

public class MyFile extends File {

public MyFile(@NotNull String pathname) {
super(pathname);
}
}
0
6 comments

Hello, 

The `@NotNull` annotation is 

ElementType.TYPE_USE

so it's considered as part of the type and you can't disable its presence while method override in your case.

0

Then, if I disable nullity inference, will @NotNull stop being inserted in generated methods? Is there a way to disable nullity inference?

0

Hello,

In case you have the annotation in base method, it's considered as part of the type thus is included in method that overrides the basic one. This behaviour is expected and can't be changed.

0

Hello,

In this case,

import org.jetbrains.annotations.NotNull;

import java.io.File;

public class MyFile extends File {

public MyFile(@NotNull String pathname) {
super(pathname);
}
}

The org.jetbrains.annotations.NotNull annotation is not in the base method. The base constructor, File(String pathname), is defined in the JDK and cannot have been annotated with org.jetbrains.annotations.NotNull. However, the annotation is still added when overriding the method. How should I understand this? Is it a bug?

0

Hello, 

Sorry, I got you wrong. Here is the link to the issue created at YouTrack for your report:

https://youtrack.jetbrains.com/issue/IDEA-279583

Please follow.

1

Great! Following the issue. Thanks a lot!

0

Please sign in to leave a comment.