Skip to content
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

[EC63] UnnecessarilyAssignValuesToVariables rule on caught exception #230

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#128](https://github.com/green-code-initiative/ecoCode/pull/128) Adding EC35 rule for Python and PHP : EC35 rule replaces EC34 with a specific use case ("file not found" sepcific)
- [#132](https://github.com/green-code-initiative/ecoCode/issues/132) Upgrade RULES.md: set proposed Python rule "Use numpy array instead of standard list" as refused with link to the justification
- [#103](https://github.com/green-code-initiative/ecoCode/issues/103) Upgrade RULES.md: set proposed HTML rule "HTML page must contain a doctype tag" as refused with link to the justification
- [#228](https://github.com/green-code-initiative/ecoCode/issues/228) Upgrade rule EC63 for java: Stop reporting caught exception even if unused

### Deleted

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void reportIfUnknow(String name, Tree tree) {
private class GetVariableVisitor extends BaseTreeVisitor {
@Override
public void visitVariable(VariableTree tree) {
if (!tree.parent().is(Kind.METHOD)) {
if (!tree.parent().is(Kind.METHOD) && !tree.parent().is(Kind.CATCH)) {
variableList.put(tree.simpleName().name(), tree);
}
super.visitVariable(tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,13 @@ public void testNonCompliantThrow() throws Exception {
public void testCompliantThrow() throws Exception {
throw new Exception("dummy");
}
}

public void testCompliantCatchException() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok for me, but, please remove "throws Exception" because no Exception really thrown.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@natixis-caen : last modification , then I will approve this PR :p

try {
int i = 1;
System.out.println(i);
} catch (Exception e) {
System.out.println("Something went wrong.");
}
}
}