False-positive on java:S5194 when only throwing exceptions

  • What language is this for?
    • Java
  • Which rule?
    • java:S5194
  • Why do you believe it’s a false-positive/false-negative?
    • because there is no way satisfy the rule without changing behavior
  • Are you using
    • SonarQube - Data Center Edition v2026.1.2 (121356)
    • SonarQube for IDE - SonarLint for Eclipse 12.2.0.84672
      • in connected mode with above server
  • How can we reproduce the problem
    public String getString() throws IOException {
        try {
            return "";
        } catch (Exception e) {
            switch (e.getCause()) { // issue created on this switch word: "Use "switch" expression to return the value from method."
            case IOException ioException -> throw ioException;
            case RuntimeException exception -> throw exception;
            default -> throw new IllegalStateException("Unexpected error was thrown from getString", e);
            }
        }
    }

Hi Vivien,

Thank you for the report! I reproduced the issue and filed SONARJAVA-6362.

Best,
Tomasz