Skip to content

Commit d5faebd

Browse files
authored
Merge pull request #8 from green-code-initiative/ISSUE_7
[ISSUE 7] EC2 rule : correction NullPointer with interface
2 parents 556fc88 + 2cf298d commit d5faebd

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313

14+
- [#7](https://github.com/green-code-initiative/ecoCode-java/issues/7) EC2 rule : correction NullPointer with interface
15+
1416
### Deleted
1517

1618
## [1.5.0] - 2024-01-06

src/main/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatement.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public List<Kind> nodesToVisit() {
6565
public void visitNode(@SuppressWarnings("NullableProblems") Tree pTree) {
6666

6767
MethodTree method = (MethodTree)pTree;
68+
if (method.block() == null) // in an interface, there are some methods without block : thus, is to avoid NPE
69+
return;
6870

6971
// reinit data structure before each method analysis
7072
variablesStruct = new VariablesPerLevelDataStructure();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* ecoCode - Java language - Provides rules to reduce the environmental footprint of your Java programs
3+
* Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package fr.greencodeinitiative.java.checks;
19+
20+
interface AvoidMultipleIfElseStatementCheck {
21+
22+
TransactionMetaData initMetaData(ITransactionFoundation transactionFoundation) throws ProgramException, MnemonicTemplateShellException;
23+
24+
}

src/test/java/fr/greencodeinitiative/java/checks/AvoidMultipleIfElseStatementTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ void test() {
2727
.onFile("src/test/files/AvoidMultipleIfElseStatement.java")
2828
.withCheck(new AvoidMultipleIfElseStatement())
2929
.verifyIssues();
30+
CheckVerifier.newVerifier()
31+
.onFile("src/test/files/AvoidMultipleIfElseStatementInterface.java")
32+
.withCheck(new AvoidMultipleIfElseStatement())
33+
.verifyNoIssues();
3034
CheckVerifier.newVerifier()
3135
.onFile("src/test/files/AvoidMultipleIfElseStatementNoIssue.java")
3236
.withCheck(new AvoidMultipleIfElseStatement())

0 commit comments

Comments
 (0)