Skip to content

GH-1564 Make JsonMessageConverter failure handling null safe and stop logging payloads - #1566

Open
seonwooj0810 wants to merge 1 commit into
spring-cloud:mainfrom
seonwooj0810:fix/issue-1564-json-converter-failure
Open

seonwooj0810 wants to merge 1 commit into
spring-cloud:mainfrom
seonwooj0810:fix/issue-1564-json-converter-failure

Conversation

@seonwooj0810

Copy link
Copy Markdown
Contributor

Fixes #1564

When fromJson fails, the fallback check String.class.isAssignableFrom(targetClass) runs even when targetClass is null. canConvertFrom explicitly accepts a null target when the content type has a type parameter, so a malformed byte[] payload hit this check and threw a NullPointerException instead of returning "not converted". The debug message of the same path also printed the whole payload.

Changes in JsonMessageConverter:

  • The byte[] → String fallback is guarded by targetClass != null, so a failed conversion with no target class now returns null.
  • The debug message of a failed conversion names the payload type and the resolved target type, plus the exception. It no longer prints the payload.
  • A type parameter that is ignored is now logged at debug level. That covers a type missing from META-INF/deserializable.types and the case where no allow-list is present at all.
  • The allow-list is a LinkedHashSet, and blank entries (for example from a, ,b or empty lines) are skipped.

Tests:

  • These fail on current main and pass with this change:
    • failedConversionOfByteArrayWithoutTargetClassReturnsNull, which threw the NPE
    • failedConversionDoesNotLogPayload
    • typeNotInAllowListIsIgnoredWithDebugMessage
    • logsIgnoredTypeParameterWhenNoAllowlistIsPresent
    • ignoresBlankAllowlistEntries
  • These guard existing behaviour:
    • failedConversionOfByteArrayToStringReturnsPayloadAsString (the String fallback still works)
    • deeplyNestedJsonIsRejected: 5000 nested objects are rejected by Jackson's default nesting limit, with null returned and no StackOverflowError.

Verification done: ./mvnw -pl spring-cloud-function-context clean install passes (302 tests, 0 failures, checkstyle included). I ran the new tests against the unmodified converter and they fail as listed above. I also checked that there is no open or recent PR touching JsonMessageConverter or referencing this issue.

…afe and stop logging payloads

A failed conversion of a byte[] payload with no target class (allowed when
the content type carries a `type` parameter) no longer fails with a
NullPointerException in the String fallback, and returns null instead.
The debug message of a failed conversion now names the payload type and
the target type rather than the payload itself.

A `type` parameter that is not listed in META-INF/deserializable.types,
or used while no allow-list is present at all, is now reported at debug
level when it is ignored. The allow-list is kept in a Set and blank
entries are skipped.

Resolves spring-cloud#1564

Signed-off-by: seonwoo_jung <79202163+seonwooj0810@users.noreply.github.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JsonMessageConverter fails with a NullPointerException and logs the payload when a conversion fails

1 participant