Skip to content

Refactor Converter type dispatch to remove chained instanceof tests#303

Merged
vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:fix/codeql-chained-type-tests
Jul 24, 2026
Merged

Refactor Converter type dispatch to remove chained instanceof tests#303
vharseko merged 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:fix/codeql-chained-type-tests

Conversation

@vharseko

Copy link
Copy Markdown
Member

Resolves both java/chained-type-tests CodeQL alerts in Converter (script/javascript). No behaviour changes; the module's 26 tests pass.

Changes

  • wrap(Parameter, Request, Scriptable) — replace the instanceof chain over the Request subtypes with Request.accept(RequestVisitor). This reuses the existing json-resource visitor API, drops the repeated setBuiltinProtoAndParent call, and lets the compiler enforce that every Request subtype is handled. The original "we shouldn't get here" fallback is preserved via a null check.
  • wrap(Parameter, Object, Scriptable, boolean) — replace the instanceof chain over unrelated types (Map, List, Function, JsonValue, JsonPointer, Request, Context) with an ordered Class -> strategy registry (LinkedHashMap), iterated in the same precedence as the previous if/else if chain. null handling and the Context.javaToJS(...) fallback are unchanged.

Notes

These types share no common hierarchy, so the second method is table-driven dispatch rather than true polymorphism — it removes the flagged instanceof chain while preserving the exact evaluation order and behaviour.

Verification

mvn -pl script/javascript -am testRhinoScriptTest: 26 run, 0 failures, 0 errors.

Resolve both java/chained-type-tests alerts in Converter:
- wrap(Parameter, Request, Scriptable): dispatch via Request.accept(
  RequestVisitor) instead of an instanceof chain over the Request subtypes
- wrap(Parameter, Object, Scriptable, boolean): dispatch via an ordered
  Class -> strategy registry, iterated in the same precedence as the
  previous if/else-if chain

Behaviour is unchanged; the javascript module tests pass.
@vharseko vharseko added codeql CodeQL static-analysis findings refactoring Code cleanup / refactoring, no behavior change labels Jul 24, 2026
@vharseko
vharseko requested a review from maximthomas July 24, 2026 06:05
@vharseko
vharseko merged commit 8d639f4 into OpenIdentityPlatform:master Jul 24, 2026
14 checks passed
@vharseko
vharseko deleted the fix/codeql-chained-type-tests branch July 24, 2026 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codeql CodeQL static-analysis findings refactoring Code cleanup / refactoring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants