KAFKA-20693: Fix NPE in AbstractHerder config-validation error handling#22592
Open
wilmerdooley wants to merge 1 commit into
Open
KAFKA-20693: Fix NPE in AbstractHerder config-validation error handling#22592wilmerdooley wants to merge 1 commit into
wilmerdooley wants to merge 1 commit into
Conversation
Signed-off-by: wilmerdooley <wilmerdooley1@gmail.com>
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.
Description
AbstractHerder.maybeAddConfigErrorsbuilds a human-readable error message by iterating over theConfigInfosreturned from config validation and appending the errors from eachConfigValue. The loop assumed everyConfigInfoit encounters has a non-nullconfigValue(), but aConfigInfo(or its innerconfigValue()) can be null, and dereferencing a nullconfigValue()produced aNullPointerExceptionin the error-handling path, so the REST layer surfaced a 500 with a confusing "Cannot invoke ... errors() because ... configValue() is null" message instead of the underlying validation error.This change adds a null-guard inside the error-message-building loop in
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/AbstractHerder.javaso that a nullConfigInfoor aConfigInfowhoseconfigValue()is null is skipped, and the existing validation error is returned to the caller as aBadRequestException.Testing Strategy
Two unit tests were added to
AbstractHerderTest:testMaybeAddConfigErrorsWithNullConfigInfoAndNullConfigValueexercises aConfigInfoslist that contains aConfigValuewhoseconfigValue()is null as well as a nullConfigInfoentry, and asserts thatmaybeAddConfigErrorsstill completes by surfacing aBadRequestException(i.e. the validation error is reported rather than crashing the REST call with an NPE).testMaybeAddConfigErrorsWithNullConfigValueAndNoErrorsexercises aConfigInfoslist whoseConfigValuehas a nullconfigValue()and no errors on the other values, and asserts thatmaybeAddConfigErrorsreturnsfalse(no validation error to report).Both tests use the existing
testHerder(),addConfigKey, andaddValuehelpers andAbstractHerder.generateResultto constructConfigInfosfixtures, so they directly cover the new null-guard branch without relying on any specific connector (e.g. Debezium) being on the classpath.JIRA: https://issues.apache.org/jira/browse/KAFKA-20693