Skip to content

Add explicit default clauses to switches flagged by java/missing-case-in-switch - #791

Merged
vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:fix-codeql-warning-tier3
Jul 31, 2026
Merged

Add explicit default clauses to switches flagged by java/missing-case-in-switch#791
vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:fix-codeql-warning-tier3

Conversation

@vharseko

Copy link
Copy Markdown
Member

Tier 3 of the warning-severity CodeQL triage (Tier 1 is #789, Tier 2 is #790). Closes all 38 java/missing-case-in-switch alerts.

What was wrong

All 38 flagged switch statements genuinely had no default: clause — that was verified for each one, not assumed. None of them is a bug today: for every enum value that is not listed, the correct behaviour is to do nothing and fall out of the switch, which is exactly what happens (falling through to a return false, to a shared return, or simply on to the next step).

The risk the rule points at is the future one: adding a value to ModificationType, SearchScope, Step, ServerStatus and friends would silently change behaviour at these 38 sites with nothing to flag it.

The change

Every flagged switch now ends with:

default:
  // No action needed for the remaining values.
  break;

The diff is additions only — no line is modified or removed, so no behaviour changes.

Explicit breaks

In Uninstaller, BindRule, BindOperationBasis, LocalBackendAddOperation and LocalBackendWorkflowElement the last case did not end with a break, which would have made the new default clause reachable by fall-through. The effect is identical, since the clause only breaks, but an explicit break; is added rather than leaving implicit fall-through behind.

Totals: 38 default: clauses, 38 comments, 43 break; (38 in the new clauses plus these 5).

Deliberately not touched

Five further switches in the same files have no default either, and are left alone because they are exhaustive — which is why CodeQL did not flag them:

Switch Why it needs no default
Utils:199, LDAPConnection:361 PasswordPolicyWarningType has exactly two values, both covered
DirectoryServer:692 complete over SubSystem
AttrHistoricalSingle:290, AttrHistoricalMultiple:575 complete over HistKey

Adding default there would be noise, so the change is scoped precisely to the 38 alerts.

Verification

  • mvn -o compile for opendj-ldap-toolkit and opendj-server-legacy — passes, with no fall-through warnings.
  • Re-checked programmatically that each default landed inside its switch body: of the switches in the touched files, 80 now have a default and 5 do not — exactly the exhaustive ones listed above.

Note for reviewers

Three files are also touched by #790: BrowserController.java, SearchOperationBasis.java and UpgradeUtils.java. There is no overlap with #789. In UpgradeUtils the two edits are close together (try-with-resources around line 336 in #790, the default around line 360 here), and in all three files both branches add the same copyright line at the same place, so a small merge conflict is likely. Suggested order: #789#790 → this one.

…-in-switch

All 38 flagged switch statements genuinely had no default clause. None of them
was a bug: for every enum value that is not listed, the correct behaviour today
is to do nothing and fall out of the switch, which is what the added clause
preserves. The change is additions only, so no behaviour is altered.

Each switch now ends with:

    default:
      // No action needed for the remaining values.
      break;

so that adding a value to one of these enums no longer changes behaviour
silently.

In Uninstaller, BindRule, BindOperationBasis, LocalBackendAddOperation and
LocalBackendWorkflowElement the last case did not end with a break, which would
have made the new default clause reachable by fall-through. The effect is the
same, since the default clause only breaks, but an explicit break is added so no
implicit fall-through is left behind.

Five further switches in the same files are deliberately left alone. They are
exhaustive and were not flagged: the two switches over PasswordPolicyWarningType
in Utils and LDAPConnection cover both of its values, and the switches over
SubSystem in DirectoryServer and over HistKey in AttrHistoricalSingle and
AttrHistoricalMultiple are likewise complete.
@vharseko
vharseko merged commit 3cd892c into OpenIdentityPlatform:master Jul 31, 2026
17 checks passed
@vharseko
vharseko deleted the fix-codeql-warning-tier3 branch July 31, 2026 07:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement java Pull requests that update java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants