While overriding code:
@Override
public void open(ExecutionContext executionContext) {
super.open(executionContext);
from: org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader
I receive an IntelliJ warning:
Not annotated parameter overrides @??? parameter less... (Strg+F1) Inspection info: Reports problems related to @Nullable and @NotNull annotations usage configured in Constant conditions & exceptions inspection.
What can I do to avoid that?
Although I can't reproduce this on AbstractItemCountingItemStreamItemReader
from this artifact
implementation group: 'org.springframework.batch', name: 'spring-batch-core', version: '4.1.2.RELEASE'
, this annotation means that the parent method has some @NotNull
/ @NonNull
annotation on the parameter, while the overriding method has no.
To fix it, you need to put the same annotation on the overriding method.
As I wrote, there is no such annotation in the version I've downloaded, but check your sources and copy the parameter annotation from there.
This warning sometimes gets buggy, so it can help to restart the IDEA. Restarting helped when I tried to write a trivial example to reproduce the warning.
Parent class:
package com.dpopov.java.stackoverflow;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
public class ParentClass {
public void nonNullMethod(@NonNull String string) {
System.out.println("S is: " + string);
}
public void nullMethod(@Nullable String string) {
System.out.println("S is: " + string);
}
}
Child class:
package com.dpopov.java.stackoverflow;
public class NonNullOverride extends ParentClass {
public static void main(String[] args) {
NonNullOverride nonNullOverride = new NonNullOverride();
nonNullOverride.nonNullMethod(null);
nonNullOverride.nullMethod(null);
}
@Override
public void nonNullMethod(final String string) {
super.nonNullMethod(string);
if (string.equals("666")) {
System.out.println("yes");
}
}
@Override
public void nullMethod(final String string) {
super.nullMethod(string);
if (string == null) {
System.out.println("I am null, it can be.");
return;
}
if (string.equals("666")) {
System.out.println("yes");
}
}
}
To be 100%-sure, I've added org.springframework.lang.NonNull
and org.springframework.lang.Nullable
annotations to the appropriate Nullable
/ NonNull
annotations of the inspection Java | Probable bugs | @NotNull/@Nullable problems
(in File | Settings | Editor | Inspections
). You do this by pressing Configure annotations
button (see the screenshot).
#nonNullMethod
:
@Nullable
method does not provoke any warning.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With