Skip to content

Fix mismatched placeholders in log and exception messages - #173

Open
vharseko wants to merge 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:fix-log-format-placeholders
Open

vharseko wants to merge 1 commit into
OpenIdentityPlatform:masterfrom
vharseko:fix-log-format-placeholders

Conversation

@vharseko

Copy link
Copy Markdown
Member

Closes code scanning alerts #29, #30, #31 (java/unused-format-argument, warning). All three are real message bugs: the argument was supplied but never rendered.

Alert Location Before After
#29 Heaplets.java logger.warn("… instantiate %s as a Heaplet", c.getName(), e) — SLF4J logs a literal %s, the class name is lost {}
#30 ResolveLocationJsonValueFunction.java String.format("$location value ({}) cannot be null …", …) — exception message shows a literal {} %s
#31 PolicyEnforcementFilter.java "Returned resource ('{}' does not match current request URI (''))" — second placeholder missing, original never printed, unbalanced parentheses ('{}') … ('{}')

Tests added:

  • HeapletsTest.shouldLogClassNameWhenHeapletCannotBeInstantiated — captures the WARN with a logback ListAppender via a heaplet whose constructor throws; failed before the fix with …instantiate [%s] as a Heaplet.
  • ResolveLocationJsonValueFunctionTest.shouldReportTheValueWhenLocationIsNull — failed before the fix with $location value ({}) cannot be null ….

No test for #31: openig-openam runs its tests on slf4j-nop, so the log line cannot be captured without adding a logging backend to the module's test dependencies; the change is confined to the format string of a // Should never happen branch.

- Heaplets: use the SLF4J "{}" placeholder instead of "%s", so the
  warning names the class that could not be instantiated
- ResolveLocationJsonValueFunction: use "%s" in String.format() instead
  of "{}", so the exception reports the $location value
- PolicyEnforcementFilter: add the missing placeholder for the request
  URI in the "returned resource does not match" error
@vharseko vharseko added bug java Pull requests that update Java code tests Adds or updates tests labels Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug java Pull requests that update Java code tests Adds or updates tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant