Skip to content

Commit

Permalink
Merge pull request #8 from green-code-initiative/ISSUE_7
Browse files Browse the repository at this point in the history
[ISSUE 7] EC2 rule : correction NullPointer with interface
  • Loading branch information
dedece35 authored Jan 22, 2024
2 parents 556fc88 + 2cf298d commit d5faebd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

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

### Deleted

## [1.5.0] - 2024-01-06
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public List<Kind> nodesToVisit() {
public void visitNode(@SuppressWarnings("NullableProblems") Tree pTree) {

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

// reinit data structure before each method analysis
variablesStruct = new VariablesPerLevelDataStructure();
Expand Down
24 changes: 24 additions & 0 deletions src/test/files/AvoidMultipleIfElseStatementInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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/>.
*/
package fr.greencodeinitiative.java.checks;

interface AvoidMultipleIfElseStatementCheck {

TransactionMetaData initMetaData(ITransactionFoundation transactionFoundation) throws ProgramException, MnemonicTemplateShellException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ void test() {
.onFile("src/test/files/AvoidMultipleIfElseStatement.java")
.withCheck(new AvoidMultipleIfElseStatement())
.verifyIssues();
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidMultipleIfElseStatementInterface.java")
.withCheck(new AvoidMultipleIfElseStatement())
.verifyNoIssues();
CheckVerifier.newVerifier()
.onFile("src/test/files/AvoidMultipleIfElseStatementNoIssue.java")
.withCheck(new AvoidMultipleIfElseStatement())
Expand Down

0 comments on commit d5faebd

Please sign in to comment.