S2637: False positive on NotNull arguments with overloaded constructors

495 views
Skip to first unread message

Dave Franken

unread,
May 26, 2017, 5:14:56 AM5/26/17
to SonarQube
Given the following class:

class NotNullTest {
  @NotNull
  private String s1;

  NotNullTest(String s1) {
    this.s1 = s1;
  }

  NotNullTest() {
    this("test");
  }
}

This will yield a warning on the bottom constructor: "s1" is marked "javax.validation.constraints.NotNull" but is not initialized in this constructor.
I believe that Sonar should be able to follow the constructor path to the top one, seeing that it initializes s1 and give no warnings.

Dave

Tibor Blenessy

unread,
May 29, 2017, 5:23:00 AM5/29/17
to Dave Franken, SonarQube
Hello Dave,

you are right that this is currently not supported and will cause an FP. I created ticket to improve the implementation SONARJAVA-2316 

Cheers

Tibor 

--
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/7a2386a5-be66-4124-b18b-0cb3ae881d46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Tibor Blenessy | SonarSource

SonarJava Developer

http://sonarsource.com 

Tibor Blenessy

unread,
May 29, 2017, 5:58:49 AM5/29/17
to Dave Franken, SonarQube
In fact, this was already reported and we already have a previous ticket for it, see SONARJAVA-2227  

Dave Franken

unread,
May 29, 2017, 6:24:40 AM5/29/17
to Tibor Blenessy, SonarQube

Okay, I tried searching for it, but could not find any relevant issue.

 

Met vriendelijke groet,


Dave Franken

Meddex

Reply all
Reply to author
Forward
0 new messages