Repository navigation
GH-1564 Make JsonMessageConverter failure handling null safe and stop logging payloads - #1566
Open
seonwooj0810 wants to merge 1 commit into
Open
seonwooj0810 wants to merge 1 commit into
seonwooj0810 wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1564
When
fromJsonfails, the fallback checkString.class.isAssignableFrom(targetClass)runs even whentargetClassisnull.canConvertFromexplicitly accepts anulltarget when the content type has atypeparameter, so a malformedbyte[]payload hit this check and threw aNullPointerExceptioninstead of returning "not converted". The debug message of the same path also printed the whole payload.Changes in
JsonMessageConverter:byte[]→Stringfallback is guarded bytargetClass != null, so a failed conversion with no target class now returnsnull.typeparameter that is ignored is now logged at debug level. That covers a type missing fromMETA-INF/deserializable.typesand the case where no allow-list is present at all.LinkedHashSet, and blank entries (for example froma, ,bor empty lines) are skipped.Tests:
mainand pass with this change:failedConversionOfByteArrayWithoutTargetClassReturnsNull, which threw the NPEfailedConversionDoesNotLogPayloadtypeNotInAllowListIsIgnoredWithDebugMessagelogsIgnoredTypeParameterWhenNoAllowlistIsPresentignoresBlankAllowlistEntriesfailedConversionOfByteArrayToStringReturnsPayloadAsString(the String fallback still works)deeplyNestedJsonIsRejected: 5000 nested objects are rejected by Jackson's default nesting limit, withnullreturned and noStackOverflowError.Verification done:
./mvnw -pl spring-cloud-function-context clean installpasses (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 touchingJsonMessageConverteror referencing this issue.