# \[Java\] SonarLint plugin does not detect return from finally block as a problem

**URL:** <https://community.sonarsource.com/t/java-sonarlint-plugin-does-not-detect-return-from-finally-block-as-a-problem/85338>\
**Category:** IntelliJ Platform\
**Tags:** bug, sonarqube-ide, java\
**Created:** [March 7, 2023, 1:49pm UTC](https://community.sonarsource.com/t/java-sonarlint-plugin-does-not-detect-return-from-finally-block-as-a-problem/85338 "2023-03-07T13:49:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/marcin/32/42810_2.png) [@marcin](https://community.sonarsource.com/u/marcin)\
**Post date:** [March 7, 2023, 1:49pm UTC](https://community.sonarsource.com/t/java-sonarlint-plugin-does-not-detect-return-from-finally-block-as-a-problem/85338/1 "2023-03-07T13:49:07Z")

</div>

Please provide

- Operating system:  
macOS Ventura  
uname -a gives:  
Darwin Kernel Version 22.3.0: Thu Jan 5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE\_ARM64\_T6000 arm64

- SonarLint plugin version:  
8.0.0.63273  
IntelliJ: Build #IU-223.8617.56, built on January 26, 2023

- Programming language you’re coding in:  
Java 17

- Is connected mode used: No

And a thorough description of the problem / question:

Consider this snippet:

```java
  private int foo() {
    try {
      return 1;
    } finally {
      return 2;
    }
  }

```

This snippet contains a code smell: [Java static code analysis: Jump statements should not occur in "finally&](https://rules.sonarsource.com/java/RSPEC-1143) (Critical).

But SonarLint does not report anything:

```auto
Analysing 'Foo.java'...
Found 0 issues and 0 hotspots

```

Looks like a bug, I think SonarLint should report this problem as Sonar does.

---

<div class="post-metadata">

**Author:** ![marcin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/marcin/32/42810_2.png) [@marcin](https://community.sonarsource.com/u/marcin)\
**Post date:** [March 7, 2023, 3:16pm UTC](https://community.sonarsource.com/t/java-sonarlint-plugin-does-not-detect-return-from-finally-block-as-a-problem/85338/2 "2023-03-07T15:16:26Z")

</div>

PS. I have the proper rule checked in the settings:

 ![image](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/d/a/da28f1ac9d586f0023088cd1e04c21280a833270.jpeg)

---

<div class="post-metadata">

**Author:** ![Damien\_Urruty](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/damien_urruty/32/43383_2.png) [@Damien\_Urruty](https://community.sonarsource.com/u/Damien_Urruty)\
**Post date:** [March 7, 2023, 4:21pm UTC](https://community.sonarsource.com/t/java-sonarlint-plugin-does-not-detect-return-from-finally-block-as-a-problem/85338/3 "2023-03-07T16:21:45Z")

</div>

Hello Marcin,

Thanks for raising this. I am not able to reproduce, an issue is correctly raised on my side.

Could you please [enable verbose logs](https://github.com/SonarSource/sonarlint-intellij/wiki/Troubleshooting#how-to-get-sonarlint-for-intellij-logs) and send them here ? Also could you send the full class instead of the method snippet, in case something else causes problems?

---

<div class="post-metadata">

**Author:** ![marcin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/marcin/32/42810_2.png) [@marcin](https://community.sonarsource.com/u/marcin)\
**Post date:** [March 7, 2023, 5:22pm UTC](https://community.sonarsource.com/t/java-sonarlint-plugin-does-not-detect-return-from-finally-block-as-a-problem/85338/4 "2023-03-07T17:22:18Z")

</div>

I put log file into attachment.

Example class:

```auto
package com.box.data.credence.integration;

public class Foo {
  private int foo() {
    try {
      return 1;
    } finally {
      return 2;
    }
  }

  public String bar() {
    return null;
  }
}

```

Please notice that the plugin runs using JDK 17 (my IntelliJ runs on JDK 17), but the project uses JDK 8 (Toolchain explicitly set in Gradle build to be JDK 8).

[sonar\_lint\_logs\_return\_finally.log](https://community.sonarsource.com/uploads/short-url/w1U8BDuy8fsYtgf7GFLolJW9sF4.log) (130.5 KB)

---

<div class="post-metadata">

**Author:** ![Damien\_Urruty](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/damien_urruty/32/43383_2.png) [@Damien\_Urruty](https://community.sonarsource.com/u/Damien_Urruty)\
**Post date:** [March 8, 2023, 8:08am UTC](https://community.sonarsource.com/t/java-sonarlint-plugin-does-not-detect-return-from-finally-block-as-a-problem/85338/5 "2023-03-08T08:08:38Z")

</div>

Thanks for the logs, I am able to reproduce. It seems that this rule is not run for test code, and I’m not sure if this is expected or not. I will forward to the team in charge.

Thanks again for reporting!

---

<div class="post-metadata">

**Author:** ![marcin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/marcin/32/42810_2.png) [@marcin](https://community.sonarsource.com/u/marcin)\
**Post date:** [March 8, 2023, 11:56am UTC](https://community.sonarsource.com/t/java-sonarlint-plugin-does-not-detect-return-from-finally-block-as-a-problem/85338/7 "2023-03-08T11:56:54Z")

</div>

Thanks for looking into it. You already have pointed me in the right direction: [Allow enabling sonar rules for test sources - #3 by reitzmichnicht](https://community.sonarsource.com/t/allow-enabling-sonar-rules-for-test-sources/3379/3)

Looks like Sonar is not checking test sources and there was already a discussion about it.
