plsql:FunctionLastStatementReturnCheck: False positive with CASE

The following code is marked with

This function should be refactored so that its last statement is a RETURN one. sonarlint(plsql:FunctionLastStatementReturnCheck)

CREATE FUNCTION test_case RETURN PLS_INTEGER AS
BEGIN
  CASE WHEN 1<2 THEN
    RETURN 1;
  ELSE
    RETURN 0;
  END CASE;
END test_case;

While the last statement is not RETURN, the CASE statement has an ELSE block, so the function will always return.

It works as expected with IF statements (no false positive):

CREATE FUNCTION test_if RETURN PLS_INTEGER AS
BEGIN
  IF 1<2 THEN
    RETURN 1;
  ELSE
    RETURN 0;
  END IF;
END test_if;
  • Rule: plsql:FunctionLastStatementReturnCheck
  • Language: Oracle PL/SQL
  • SonarQube 9.9.1

Hello @Peter0 and thank you for reporting this!

I confirm this is a false positive.
I’ve added an issue to our backlog to tackle in future sprints.
You can follow it here.