Skip to content

Refactor CliException to unchecked exception (Sonar S1160) #543

@redcatbear

Description

@redcatbear

Situation

Sonar complains about CliException being a checked exception (rule S1160: "Checked exceptions should not be thrown"). In modern Java design, unchecked exceptions are often preferred for situations where the caller is not expected to recover, such as CLI argument validation errors where the program must terminate after reporting the error. Currently, CliException extends Exception, forcing many method signatures to declare throws CliException.

Implementation Hints

  1. Modify org.itsallcode.openfasttrace.core.cli.CliException to extend RuntimeException instead of Exception.
  2. Remove redundant throws CliException clauses from method signatures in CommandLineInterpreter, CliStarter, and other relevant classes.
  3. Keep the @throws CliException Javadoc where useful for documentation of the API contract.
  4. Ensure the centralized error handling in CliStarter.mainDelegate continues to catch CliException to report errors to the user gracefully.

Acceptance Criteria

  1. CliException is a RuntimeException.
  2. No more Sonar S1160 warnings for CliException.
  3. The CLI still gracefully handles invalid arguments and prints the error message to System.err as before.
  4. mvn verify passes, including all tests and self-trace checks.

Metadata

Metadata

Assignees

Labels

refactoringCode improvement without behavior change
No fields configured for Refactoring.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions