-
Notifications
You must be signed in to change notification settings - Fork 47
[69] NullPointer exception in eco code java Sonar plugin #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package files; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please rename this test class with an explicit name corresponding to use case instead of "2" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will done it if you want after the merge of this PR (if you don't have time to do it) |
||
|
|
||
| import java.io.FileWriter; | ||
| import java.io.IOException; | ||
|
|
||
| /* | ||
| * ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs | ||
| * Copyright © 2023 Green Code Initiative (https://www.ecocode.io) | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
| public class FreeResourcesOfAutoCloseableInterface2 { | ||
|
|
||
| /** | ||
| * The first methods adds a "try" in the stack used to follow if the code is in a try | ||
| */ | ||
| public void callingMethodWithTheTry() throws IOException { | ||
| try { | ||
| calledMethodWithoutTry(); | ||
| } finally { | ||
| // Empty block of code | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The "try" should have been poped from the stack before entering here | ||
| */ | ||
| private void calledMethodWithoutTry() throws IOException { | ||
| FileWriter myWriter = new FileWriter("somefilepath"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, but for me, this use case is an "non compliant" case. |
||
| myWriter.write("something"); | ||
| myWriter.flush(); | ||
| myWriter.close(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.