Skip to content

Replace chained instanceof filter dispatch with the existing FilterVisitor - #145

Open
vharseko wants to merge 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:chained-type-tests
Open

vharseko wants to merge 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:chained-type-tests

Conversation

@vharseko

Copy link
Copy Markdown
Member

Summary

Closes the last remaining CodeQL note-severity category, java/chained-type-tests (4 alerts).

  • ObjectNormalizerFacade.normalizeFilter (12-way instanceof chain) and AbstractFilterTranslator.createLeafExpression (9-way instanceof chain) both dispatch on the framework's own Filter subtypes, and the framework already ships a FilterVisitor interface for exactly this purpose (see FilteredResultsHandlerVisitor for a prior-art example). Rewrote both as proper visitor dispatch instead of an instanceof chain.
    • AbstractFilterTranslator's visitor is a private, non-static inner class so its visitXxxFilter methods reach the enclosing instance's protected createXxxExpression(...) methods — preserving the class's whole point, which is letting connector subclasses override those methods.
    • Caught a real regression during the refactor: the original instanceof chain was implicitly null-safe (instanceof on null is always false, falling through to the else branch), but filter.accept(...) throws NullPointerException on a null filter. Fixed in both files (restored the null check at the entry points, and routed the AND/OR/NOT recursion in ObjectNormalizerFacade back through the null-checked public method rather than calling .accept directly on possibly-null sub-filters). Added a regression test (testNullFilterReturnsNull) plus one for the previously-untested presence-filter passthrough branch (testPresenceFilterPassedThroughUnchanged).
  • The other two java/chained-type-tests alerts — EqualsHashCodeBuilder.append (dispatches on primitive array component types) and SQLUtil's JDBC parameter binding (dispatches on Integer/Double/Blob/Timestamp/...) — are dismissed on GitHub as won't-fix: both dispatch on final JDK types we don't own, so a visitor/polymorphism-based fix is not possible.

Test plan

  • New tests: ObjectNormalizerFacadeTests.testPresenceFilterPassedThroughUnchanged, testNullFilterReturnsNull.
  • mvn install -DskipITs on connector-framework, connector-framework-internal, OpenICF-ldap-connector, OpenICF-dbcommon, OpenICF-xml-connector (incl. their existing filter-translator test suites) — all green, 988 tests, 0 failures.

…sitor

Closes java/chained-type-tests for ObjectNormalizerFacade.normalizeFilter
(12 tests) and AbstractFilterTranslator.createLeafExpression (9 tests):
both already had a real Filter type hierarchy and a FilterVisitor
interface available, so the instanceof chains become proper visitor
dispatch instead of a mechanical alternative. Behavior-preserving,
including a null-safety edge case the first pass of this refactor
briefly broke (caught by the existing test suite, fixed, and locked in
with a new regression test).

The other two java/chained-type-tests alerts (EqualsHashCodeBuilder,
SQLUtil) are dismissed on GitHub as won't-fix: they dispatch on final
JDK types (primitive array component types / Integer, Double, Blob,
Timestamp, ...) that a visitor pattern cannot be added to.
@vharseko vharseko added java Pull requests that update java code framework OpenICF-java-framework refactoring Code cleanup / tech debt, no behavior change tests Test additions or fixes labels Sep 23, 2026

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

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

Labels

framework OpenICF-java-framework java Pull requests that update java code refactoring Code cleanup / tech debt, no behavior change tests Test additions or fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants