Sonar java - support @Nullable from checker framework

861 views
Skip to first unread message

Jiří Pejchal

unread,
Apr 9, 2018, 4:16:17 AM4/9/18
to SonarQube
Hi,

in recent versions google guava migrated from jsr305 @Nullable to Checker Framework @NullableDecl.


E.g. Strings.java:
public static String nullToEmpty(@NullableDecl String string) {
    return (string == null) ? "" : string;
}


Now the code:

String notNull = Strings.nullToEmpty(string);

reports for S4449 the following warning:

Argument can be null.
Annotate the parameter with @javax.annotation.Nullable in method 'nullToEmpty' declaration, or make sure that null can not be passed as argument.


Could "S4449 Nullness of parameters should be guaranteed" also support @Nullable/@NullableDecl from checker framework?

Jiri Pejchal

Michael Gumowski

unread,
Jun 5, 2018, 11:04:16 AM6/5/18
to Jiří Pejchal, SonarQube
Hello Jiri,

I'm not able to reproduce it with latest released version of SonarJava (5.4). Could you please provide a self-contained code-snippet reproducing the issue? (maybe using a small maven project with only a dependency to guava and a single file?)

I would also appreciate if you could also precise which version of guava you are using.

Regards,
Michael

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/ec5cc773-021f-410f-aa8b-1f4a2739ba08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Michael Gumowski | SonarSource
Software Developer, Language Team
https://www.sonarsource.com

Michael Gumowski

unread,
Jun 6, 2018, 5:56:46 AM6/6/18
to Jiří Pejchal, SonarQube
Hello,

From another feedback I have been able to reproduce the issue. Fixing tickets SONARJAVA-2777  (and then SONARJAVA-2776) will remove the various FPs you are observing.

Regards,
Michael

Jiri Pejchal

unread,
Jun 6, 2018, 6:19:08 AM6/6/18
to michael....@sonarsource.com, sona...@googlegroups.com
Thanks,

I was using guava 25.0-jre. 

Note: guava 25.1 for java 8 migrated from @NullableDecl to org.checkerframework.checker.nullness.qual.Nullable.

Regards,
Jiri Pejchal
Reply all
Reply to author
Forward
0 new messages