SonarJava false positive with @CheckForNull parameter

72 views
Skip to first unread message

hexag...@gmail.com

unread,
Mar 23, 2018, 7:39:25 AM3/23/18
to SonarQube
Hello all,

The following code gives me a "NullPointerException" will be thrown when invoking method "m2()". It looks like passing x to m1 makes the analyser believe that x is nullable, just because the parameter is marked @CheckForNull. However, the @Nonnull in m0 should have made it clear that that is not the case.

I don't think a parameter annotation should be used to say something about the actual argument in this case.

package nl.donna.pm.planversiekern.dto.muteer.mutator;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

public class UnexpectedNpeIssue {

void m0(@Nonnull String x) {
m1(x);
m2(x);
}

private void m1(@CheckForNull String x) {
}

private void m2(String x) {
x.toString();
}
}

Thanks,
Danny

Danny van Bruggen

unread,
Mar 23, 2018, 9:15:37 AM3/23/18
to SonarQube
Okay, this was solved by upgrading from 5.1.1 to 5.2. Sorry for the noise.

--
You received this message because you are subscribed to a topic in the Google Groups "SonarQube" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonarqube/Z3oYjUva9JE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonarqube+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/9a31ed9e-2046-4b23-9f14-6652e85cc0bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages