# S2637 triggers on Java primitives

**URL:** <https://community.sonarsource.com/t/s2637-triggers-on-java-primitives/49722>\
**Category:** Report False-positive / False-negative...\
**Tags:** java\
**Created:** [September 14, 2021, 9:47am UTC](https://community.sonarsource.com/t/s2637-triggers-on-java-primitives/49722 "2021-09-14T09:47:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andreas\_Magnusson](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/andreas_magnusson/32/3660_2.png) [@Andreas\_Magnusson](https://community.sonarsource.com/u/Andreas_Magnusson)\
**Post date:** [September 14, 2021, 9:47am UTC](https://community.sonarsource.com/t/s2637-triggers-on-java-primitives/49722/1 "2021-09-14T09:47:56Z")

</div>

Version used: \* Community Edition Version 9.0.1 (build 46107)

We are getting hits on S2637 “@NonNull” values should not be set to null in code like this:

```auto
package simple;

import org.eclipse.jdt.annotation.NonNullByDefault;

@NonNullByDefault
class Example {
  boolean falseByDefault;
  Boolean nullByDefault;

  int zeroByDefault;
  Integer nullByDefault2;

  public Example() {
    nullByDefault = false;
    nullByDefault2 = 200;
  }
}

```

SonarQube reports that falseByDefault is not initialized in the constructor. But the Java specification says that falseByDefault is indeed… false by default. So how should it be able to be null? I don’t get it.

Now, some might say that this is “bad code”, but if that is the case this should be a code smell. It is as far as I understand it not a @NonNull violation.

Not sure what the data point is worth, but Eclipse Java NonNull detection does not complain.

/Andreas

---

<div class="post-metadata">

**Author:** ![Quentin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/quentin/32/74716_2.png) [@Quentin](https://community.sonarsource.com/u/Quentin)\
**Post date:** [September 23, 2021, 9:57am UTC](https://community.sonarsource.com/t/s2637-triggers-on-java-primitives/49722/4 "2021-09-23T09:57:20Z")

</div>

Hello @Andreas_Magnusson

I agree with you, this case should not be reported by this rule. Ticket created to improve the situation: [SONARJAVA-4025](https://jira.sonarsource.com/browse/SONARJAVA-4025).

Thanks for taking the time to report this problem with a clear reproducer.

Best,  
Quentin

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [September 30, 2021, 9:58am UTC](https://community.sonarsource.com/t/s2637-triggers-on-java-primitives/49722/5 "2021-09-30T09:58:14Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
