Skip to content

Conversation

@max-208
Copy link
Contributor

@max-208 max-208 commented May 20, 2025

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.

@rducasse rducasse self-assigned this May 21, 2025
Copy link

@rducasse rducasse left a 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")

@max-208 max-208 changed the title [Challenge-25][GCI1166]new rule "don't catch runtime exceptions" [Challenge-25][GCI1166][S.T.E.P] new rule "don't catch runtime exceptions" May 21, 2025
@rducasse
Copy link

Thx. Build and tests now working
Please now use the id GCI96

@github-actions
Copy link

This PR has been automatically marked as stale because it has no activity for 30 days.
Please add a comment if you want to keep the issue open. Thank you for your contributions!

@github-actions github-actions bot added the stale label Jun 26, 2025
@dedece35 dedece35 requested a review from Copilot July 6, 2025 20:40
Copy link

Copilot AI left a 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 AvoidRuntimeExceptions rule to detect catches of RuntimeException subtypes
  • Add unit tests in AvoidRuntimeExceptionsTest and integration tests in GCIRulesIT
  • Register the new rule in creedengo_way_profile.json, JavaCheckRegistrar, and document it in CHANGELOG.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 Type conflicts with class naming conventions and starts with an uppercase letter. Consider renaming it to exceptionType or caughtType to 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.RuntimeException is incorrect. It should be import java.lang.RuntimeException; to match the actual package.
import java.lang.runtime.RuntimeException;

@dedece35
Copy link
Member

dedece35 commented Jul 6, 2025

waiting for PR green-code-initiative/creedengo-rules-specifications#401 to check this rule

@github-actions github-actions bot removed the stale label Jul 7, 2025
## [Unreleased]

### Added
- [#106](https://github.com/green-code-initiative/creedengo-java/pull/106) Add new Java rule GCI96 - Avoid Catching Runtime exceptions
Copy link
Member

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

@dedece35
Copy link
Member

please also check Copilot review ideas

@github-actions
Copy link

This PR has been automatically marked as stale because it has no activity for 30 days.
Please add a comment if you want to keep the issue open. Thank you for your contributions!

@github-actions github-actions bot added the stale label Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants