-
Notifications
You must be signed in to change notification settings - Fork 47
[Challenge-25][GCI1166][S.T.E.P] new rule "don't catch runtime exceptions" #106
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?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Can you update CHANGELOG.md
- Integration test fails when mvn install because of missing exception imports ("cannot find symbol")
.../src/main/java/org/greencodeinitiative/creedengo/java/checks/DontCatchRuntimeExceptions.java
Outdated
Show resolved
Hide resolved
.../src/main/java/org/greencodeinitiative/creedengo/java/checks/DontCatchRuntimeExceptions.java
Outdated
Show resolved
Hide resolved
src/main/java/org/greencodeinitiative/creedengo/java/checks/DontCatchRuntimeExceptions.java
Outdated
Show resolved
Hide resolved
|
Thx. Build and tests now working |
|
This PR has been automatically marked as stale because it has no activity for 30 days. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new Sonar Java rule (GCI96) that flags any catch of runtime exceptions (excluding IllegalArgumentException and its subtypes), along with corresponding unit and integration tests and registration updates.
- Implement
AvoidRuntimeExceptionsrule to detect catches ofRuntimeExceptionsubtypes - Add unit tests in
AvoidRuntimeExceptionsTestand integration tests inGCIRulesIT - Register the new rule in
creedengo_way_profile.json,JavaCheckRegistrar, and document it inCHANGELOG.md
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/java/org/greencodeinitiative/creedengo/java/checks/AvoidRuntimeExceptionsTest.java | Add JUnit test harness for the new rule |
| src/test/files/AvoidRuntimeExceptions.java | Provide sample code with catch blocks to trigger the rule |
| src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRuntimeExceptions.java | Implement rule logic to report catching runtime exceptions |
| src/main/java/org/greencodeinitiative/creedengo/java/JavaCheckRegistrar.java | Register AvoidRuntimeExceptions in the plugin |
| src/main/resources/org/greencodeinitiative/creedengo/java/creedengo_way_profile.json | Include GCI96 in the default quality profile |
| src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java | Add integration tests for rule GCI96 |
| src/it/test-projects/creedengo-java-plugin-test-project/src/main/java/.../AvoidRuntimeExceptions.java | Add test project input mirroring the sample file |
| CHANGELOG.md | Document the addition of rule GCI96 |
Comments suppressed due to low confidence (3)
src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRuntimeExceptions.java:46
- [nitpick] The variable name
Typeconflicts with class naming conventions and starts with an uppercase letter. Consider renaming it toexceptionTypeorcaughtTypeto follow camelCase and improve clarity.
String Type = catchTree.parameter().type().symbolType().name();
CHANGELOG.md:13
- [nitpick] This entry introduces a new rule and should be listed under the Added section instead of Changed to accurately reflect its addition.
- [#106](https://github.com/green-code-initiative/creedengo-java/pull/106) Add new Java rule GCI96 - Avoid Runtime exceptions
src/test/files/AvoidRuntimeExceptions.java:24
- The import path
java.lang.runtime.RuntimeExceptionis incorrect. It should beimport java.lang.RuntimeException;to match the actual package.
import java.lang.runtime.RuntimeException;
src/it/java/org/greencodeinitiative/creedengo/java/integration/tests/GCIRulesIT.java
Outdated
Show resolved
Hide resolved
...ject/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRuntimeExceptions.java
Show resolved
Hide resolved
src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRuntimeExceptions.java
Show resolved
Hide resolved
src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRuntimeExceptions.java
Outdated
Show resolved
Hide resolved
src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRuntimeExceptions.java
Outdated
Show resolved
Hide resolved
|
waiting for PR green-code-initiative/creedengo-rules-specifications#401 to check this rule |
...ject/src/main/java/org/greencodeinitiative/creedengo/java/checks/AvoidRuntimeExceptions.java
Show resolved
Hide resolved
| ## [Unreleased] | ||
|
|
||
| ### Added | ||
| - [#106](https://github.com/green-code-initiative/creedengo-java/pull/106) Add new Java rule GCI96 - Avoid Catching Runtime exceptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please change ID GCI96 to GCI98 in all this PR, because PR green-code-initiative/creedengo-rules-specifications#401 has just been merged
|
please also check Copilot review ideas |
|
This PR has been automatically marked as stale because it has no activity for 30 days. |
You shouldn't catch runtime exceptions, but rather check your code before the error. a runtime exception causes the creation of large exception objects for nothing.