Skip to content

SONARJAVA-6053 Fix S112 false positive for checked exception#5648

Draft
rombirli wants to merge 1 commit into
masterfrom
rombirli/SONARJAVA-6053-fp-s112-runtimeexception-wrapping
Draft

SONARJAVA-6053 Fix S112 false positive for checked exception#5648
rombirli wants to merge 1 commit into
masterfrom
rombirli/SONARJAVA-6053-fp-s112-runtimeexception-wrapping

Conversation

@rombirli
Copy link
Copy Markdown
Contributor

@rombirli rombirli commented Jun 2, 2026


Summary by Gitar

  • Test coverage:
    • Added test cases to RawExceptionCheckSample.java to reproduce S112 false positives.
    • Added scenarios for wrapping checked exceptions with and without messages or specific causes.

This will update automatically on new commits.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 2, 2026

Agentic Analysis: Early Results

Agentic Analysis and Context Augmentation are available on your project. Here are some issues that could have been prevented. Follow the links to learn how to put them into action.

44 issue(s) found across 1 file(s):

Rule File Line Message
java:S100 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 39 Rename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.
java:S2142 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 42 Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 43 Replace generic exceptions with specific library exceptions or a custom exception.
java:S100 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 47 Rename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 51 Replace generic exceptions with specific library exceptions or a custom exception.
java:S2142 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 52 Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 53 Replace generic exceptions with specific library exceptions or a custom exception.
java:S100 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 57 Rename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 61 Replace generic exceptions with specific library exceptions or a custom exception.
java:S100 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 65 Rename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 70 Replace generic exceptions with specific library exceptions or a custom exception.
java:S100 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 74 Rename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.
java:S2142 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 77 Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 78 Replace generic exceptions with specific library exceptions or a custom exception.
java:S100 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 82 Rename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.
java:S1181 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 85 Catch Exception instead of Throwable.
java:S2142 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 85 Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 86 Replace generic exceptions with specific library exceptions or a custom exception.
java:S100 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 90 Rename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 94 Replace generic exceptions with specific library exceptions or a custom exception.
java:S2142 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 95 Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.
java:S100 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 100 Rename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 104 Replace generic exceptions with specific library exceptions or a custom exception.
java:S2147 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 105 Combine this catch with the one at line 103, which has the same body. (sonar.java.source not set. Assuming 7 or greater.)
java:S2142 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 105 Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 106 Replace generic exceptions with specific library exceptions or a custom exception.
java:S100 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 110 Rename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 114 Replace generic exceptions with specific library exceptions or a custom exception.
java:S2142 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 115 Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 116 Replace generic exceptions with specific library exceptions or a custom exception.
java:S100 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 120 Rename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 125 Replace generic exceptions with specific library exceptions or a custom exception.
java:S2142 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 126 Either re-interrupt this method or rethrow the "InterruptedException" that can be caught here.
java:S112 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 127 Replace generic exceptions with specific library exceptions or a custom exception.
java:S2325 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 131 Make "readFromBlockingSource" a "static" method.
java:S1130 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 131 Remove the declaration of thrown exception 'java.io.IOException', as it cannot be thrown from method's body.
java:S1130 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 131 Remove the declaration of thrown exception 'java.lang.InterruptedException', as it cannot be thrown from method's body.
java:S3400 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 132 Remove this method and declare a constant for this value.
java:S2325 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 135 Make "readPrivilegedValue" a "static" method.
java:S1130 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 135 Remove the declaration of thrown exception 'java.security.PrivilegedActionException', as it cannot be thrown from method's body.
java:S3400 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 136 Remove this method and declare a constant for this value.
java:S2325 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 139 Make "invokeReflectively" a "static" method.
java:S1130 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 139 Remove the declaration of thrown exception 'java.lang.reflect.InvocationTargetException', as it cannot be thrown from method's body.
java:S3400 java-checks-test-sources/default/src/main/java/checks/RawExceptionCheckSample.java 140 Remove this method and declare a constant for this value.

Analyzed by SonarQube Agentic Analysis in 5.2 s

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title SONARJAVA-6053 Fix S112 false positive for checked exception SONARJAVA-6053 Fix S112 false positive for checked exception Jun 2, 2026
@hashicorp-vault-sonar-prod
Copy link
Copy Markdown
Contributor

hashicorp-vault-sonar-prod Bot commented Jun 2, 2026

SONARJAVA-6053

@gitar-bot
Copy link
Copy Markdown

gitar-bot Bot commented Jun 2, 2026

CI failed: The build failed due to test regressions in `RawExceptionCheckTest` caused by the recent rule changes, alongside a localized failure in `JasperTest` related to JSP transpilation.

Overview

The build failed in the java-checks module due to 1614 test failures in RawExceptionCheckTest and an additional failure in JasperTest. The primary issue is a change in the expected behavior of the S112 rule, while the JasperTest failure appears related to JSP compilation errors.

Failures

Rule S112 Logic Regression (confidence: high)

  • Type: test
  • Affected jobs: java-checks build jobs
  • Related to change: yes
  • Root cause: The changes to address S112 false positives altered the rule's detection behavior for RuntimeException, causing 27 issues to be raised instead of the expected 19. This suggests the rule is now flagging previously compliant or ignored exception-wrapping patterns.
  • Suggested fix: Review the visitor logic in RawExceptionCheck to ensure RuntimeException exclusion is consistent. Update the test expectations in RawExceptionCheckTest if the new flagging behavior is desired, or adjust the rule to preserve original compliance.

JSP Transpilation Failure (confidence: high)

  • Type: test
  • Affected jobs: java-jsp test suite
  • Related to change: yes
  • Root cause: JasperTest failed during the test_exception_handling scenario with org.apache.jasper.JasperException (Unterminated <%= tag) and java.lang.ClassFormatError. This indicates potential corruption or syntax issues in the JSP test resources triggered by the recent environment or code changes.
  • Suggested fix: Validate the JSP files in java-jsp/src/main/webapp/WEB-INF/jsp/ for correct syntax, specifically checking that all expression tags are properly closed.

Summary

  • Change-related failures: 2 (Regression in rule S112 logic and JSP transpilation error in JasperTest).
  • Infrastructure/flaky failures: 0.
  • Recommended action: First, fix the regression in RawExceptionCheck to match the expected number of issues. Then, verify the JSP test resources to resolve the JasperException.
Code Review ✅ Approved

Introduces a fix for the S112 false positive involving checked exceptions and adds comprehensive test coverage for exception wrapping scenarios. No issues found.

Tip

Comment Gitar fix CI or enable auto-apply: gitar auto-apply:on

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant