# FP java:S2259 reports possible NPE for switch case after null case

**URL:** <https://community.sonarsource.com/t/fp-java-s2259-reports-possible-npe-for-switch-case-after-null-case/152170>\
**Category:** Report False-positive / False-negative...\
**Tags:** false-positive, java21, jspecify, java\
**Created:** [November 10, 2025, 10:12am UTC](https://community.sonarsource.com/t/fp-java-s2259-reports-possible-npe-for-switch-case-after-null-case/152170 "2025-11-10T10:12:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahubold](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ahubold/32/70_2.png) [@ahubold](https://community.sonarsource.com/u/ahubold)\
**Post date:** [November 10, 2025, 10:12am UTC](https://community.sonarsource.com/t/fp-java-s2259-reports-possible-npe-for-switch-case-after-null-case/152170/1 "2025-11-10T10:12:10Z")

</div>

- SonarQube Community Build 25.11.0.114957
- Java Code
- Rule S2259 Null pointers should not be dereferenced

S2259 reports an issue for the the following Java code:

```java
package org.example;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
public class SwitchWithNullCase {
  public String m(@Nullable Object o) {
    return switch (o) {
      case null -> "";
      default -> o.toString(); // FP: A "NullPointerException" could be thrown; "o" is nullable here.
    };
  }
}

```

I’ve attached the above source as minimal maven project.

[test.zip](https://community.sonarsource.com/uploads/short-url/lv9w85QEIgmXwS3nhcUpjI0CcMv.zip) (1.9 KB)

Cheers  
Andreas

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [November 11, 2025, 8:42am UTC](https://community.sonarsource.com/t/fp-java-s2259-reports-possible-npe-for-switch-case-after-null-case/152170/3 "2025-11-11T08:42:43Z")

</div>

Hey there.

While I’m sure you’re already aware, for completeness, I’m linking @ganncamp’s answer on your other thread here. 🙂

> [@FP java:S2259 reports possible NPE for unboxing a Boolean that is not null](https://community.sonarsource.com/t/fp-java-s2259-reports-possible-npe-for-unboxing-a-boolean-that-is-not-null/151634/12):
>
> Hi, We have stopped working on java:S2259 which is only shipped today in Community Build. It will not receive bug fixes. We have shifted our focus to javabugs:S2259. When there is development time to be spent on nullness, it will be spent on javabugs:S2259. &nbsp; HTH, Ann
