# Nullpointer on SonarJava in version \>= 5.9

**URL:** <https://community.sonarsource.com/t/nullpointer-on-sonarjava-in-version-5-9/4169>\
**Category:** SonarQube Server / Community Build\
**Tags:** java\
**Created:** [November 12, 2018, 1:18pm UTC](https://community.sonarsource.com/t/nullpointer-on-sonarjava-in-version-5-9/4169 "2018-11-12T13:18:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruben\_Ruiz](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ruben_ruiz/32/4644_2.png) [@Ruben\_Ruiz](https://community.sonarsource.com/u/Ruben_Ruiz)\
**Post date:** [November 12, 2018, 1:18pm UTC](https://community.sonarsource.com/t/nullpointer-on-sonarjava-in-version-5-9/4169/1 "2018-11-12T13:18:06Z")

</div>

Hello,

SonarJava fails with a Nullpointer after trying to analyze the next class:

```auto
public class SomeClass {

    private SomeClass() {
        throw new IllegalAccessError("Utility class");
    }

    @Nonnull
    public static <T> OtherClass<Optional<T>> doSomething() {
        return (oldValue, newValue) -> newValue.isPresent() ? newValue : oldValue;
    }
}

```

OtherClass is:

```auto
public interface OtherClass<T> {
    T combine(T oldValue, T newValue);
}

```

We get a Nullpointer when we try to run Sonar Analysis using Maven

```auto
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.5.0.1254:sonar (default-cli) on project some-project: SonarQube is unable to analyze file : '/path/SomeClass.java': NullPointerException -> [Help 1]

```

Sonar Version: 6.7.5

Plugin Version: 3.5.0

We reproduced the error with SonarJava plugin on version 5.9 and 5.9.1

It doesn’t happen with SonarJava 5.8.0, so we downgraded the plugin to that version.

Thank you

---

<div class="post-metadata">

**Author:** ![Michael](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/michael/32/43_2.png) [@Michael](https://community.sonarsource.com/u/Michael)\
**Post date:** [November 12, 2018, 2:06pm UTC](https://community.sonarsource.com/t/nullpointer-on-sonarjava-in-version-5-9/4169/2 "2018-11-12T14:06:03Z")

</div>

Hello,

Thanks for the feedback. Unfortunately, your reproducer does not compile. Can you fix it?

In particular, `SomeClass` is not parameterized in the class declaration (and does not extends/implements anything), while its obviously a parameterized class, looking at `doSomething()` method signature.

Thanks in advance,  
Michael

* * *
Sorry, forgot to add something:
- Could you also provide the **full log of the analysis** (maybe in debug mode), so we will be able to see which rule/component raise the NPE?
- The Nonnull annotation which you use is also not defined, please provide the fully qualified name.

---

<div class="post-metadata">

**Author:** ![Ruben\_Ruiz](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ruben_ruiz/32/4644_2.png) [@Ruben\_Ruiz](https://community.sonarsource.com/u/Ruben_Ruiz)\
**Post date:** [November 12, 2018, 3:27pm UTC](https://community.sonarsource.com/t/nullpointer-on-sonarjava-in-version-5-9/4169/3 "2018-11-12T15:27:31Z")

</div>

Hello,

You’re right. I updated the previous post with something that should compile in JDK 8

Best regards

---

<div class="post-metadata">

**Author:** ![Michael](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/michael/32/43_2.png) [@Michael](https://community.sonarsource.com/u/Michael)\
**Post date:** [November 12, 2018, 4:11pm UTC](https://community.sonarsource.com/t/nullpointer-on-sonarjava-in-version-5-9/4169/4 "2018-11-12T16:11:15Z")

</div>

Thanks for the update.

Unfortunately, I have not been able to reproduce it on my side. Note that I assumed the annotation to be `@javax.annotation.Nonnull`. On my machine, your example compiles, and passes the analysis without failing, with absolutely all the rules from SonarJava enabled (version `5.9.1.16423`).

Could you share the logs of your analysis? It would help to know the full stacktrace associated to the NPE. You may want to run your analysis with **debug** mode.

---

<div class="post-metadata">

**Author:** ![Michael](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/michael/32/43_2.png) [@Michael](https://community.sonarsource.com/u/Michael)\
**Post date:** [November 23, 2018, 3:05pm UTC](https://community.sonarsource.com/t/nullpointer-on-sonarjava-in-version-5-9/4169/5 "2018-11-23T15:05:11Z")

</div>

Hello @Ruben_Ruiz,

Sorry, I forgot to answer you earlier. Thanks to your edit, I reproduced the issue. This is the same case as the following:

> [@NPE with lambdas in S4738](https://community.sonarsource.com/t/npe-with-lambdas-in-s4738/4233):
>
> SonarQube Developer v7.4, sonar-java v5.9.1 build 16423 (from Marketplace) Error: Caused by: org.sonar.java.AnalysisException: SonarQube is unable to analyze file : '/Users/jschroeder/git/crash\_repo/src/main/java/hello/HelloWorld.java' at org.sonar.java.ast.JavaAstScanner.simpleScan(JavaAstScanner.java:105) at org.sonar.java.ast.JavaAstScanner.scan(JavaAstScanner.java:68) at org.sonar.java.JavaSquid.scanSources(JavaSquid.java:116) at org.sonar.java.JavaSquid.sc…

So the conclusion is going to be the same: This is a bug in rule S4738, which will be handled by [SONARJAVA-2967](https://jira.sonarsource.com/browse/SONARJAVA-2967).

If you need a workaround, you can temporarily disable rule [squid:S4738](https://rules.sonarsource.com/java/RSPEC-4738), or exclude the file which is causing the analysis to fail.

Regards,  
Michael

---

<div class="post-metadata">

**Author:** ![Ruben\_Ruiz](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ruben_ruiz/32/4644_2.png) [@Ruben\_Ruiz](https://community.sonarsource.com/u/Ruben_Ruiz)\
**Post date:** [November 26, 2018, 4:24pm UTC](https://community.sonarsource.com/t/nullpointer-on-sonarjava-in-version-5-9/4169/6 "2018-11-26T16:24:26Z")

</div>

Hello @Michael,

We have excluded the file until the issue is fixed.

Thank you very much for your answer and your efforts in reproducing the issue.
