False positive on "@NonNull" values should not be set to null (squid:S2637)

150 views
Skip to first unread message

xavier....@gmail.com

unread,
Apr 6, 2017, 3:13:25 AM4/6/17
to SonarQube
I've got several false positives reported by the S2637 rule. 

Here's an example :


import android.support.annotation.NonNull;

public class Foo {


   
@NonNull
   
public final String tag;
 
   
public Foo() {
       
// "tag" is marked "android.support.annotation.NonNull" but is not initialized in this constructor.  
       
this("default_tag");

   
}
 
   
public Foo(@NonNull String tag) {
       
this.tag = tag;
   
}
}

It does detect in the second constructor that the field is correctly set to a non null value, but doesn't understand in the first one that we redirect to another constructor with a non null parameter. 

Michael Gumowski

unread,
Apr 6, 2017, 4:15:08 AM4/6/17
to xavier....@gmail.com, SonarQube
Hello Xavier,

Thanks for reaching us through our mailing list, and thanks a lot for the reproducer. I reproduced the issue with the latest version of SonarJava, but it never hurts to also provide the version of SonarJava that you are using when reporting a problem. It usually help us pinpoint issues and potential solutions.

The same issue has already been reported in this thread from the Mailing List (using another non-null annotation), and the following JIRA ticket has been created to handle the issue: SONARJAVA-2227

Cheers,
Michael

PS: Note that we usually also appreciate on this ML the basic rules of courtesy, such as "hello", "thank you", etc.

--
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/6313ef2b-07c5-447e-84fd-6a9e60a57b79%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com
Reply all
Reply to author
Forward
0 new messages