Skip to content

Validate the inputStream argument in KeyVal.inputStream#2525

Open
vasiliy-mikhailov wants to merge 1 commit into
jhy:masterfrom
vasiliy-mikhailov:fix/keyval-inputstream-null-validation
Open

Validate the inputStream argument in KeyVal.inputStream#2525
vasiliy-mikhailov wants to merge 1 commit into
jhy:masterfrom
vasiliy-mikhailov:fix/keyval-inputstream-null-validation

Conversation

@vasiliy-mikhailov

@vasiliy-mikhailov vasiliy-mikhailov commented Jun 26, 2026

Copy link
Copy Markdown

HttpConnection.KeyVal.inputStream(InputStream) calls Validate.notNullParam(value, "inputStream") — it validates the unrelated value field instead of the inputStream argument. So inputStream(null) is silently accepted (a null stream is stored), while a KeyVal whose value is null would fail with a misleading "The parameter 'inputStream' must not be null."

Validate the argument that's actually used. Extended the existing inputStream() test.

Verifying this change

The added HttpConnectionTest#inputStream case fails before this change and passes after:

Before the fix:

$ mvn test -Dtest=HttpConnectionTest
[INFO] Running org.jsoup.helper.HttpConnectionTest
[ERROR] Tests run: 42, Failures: 1, Errors: 0, Skipped: 0 <<< FAILURE!
org.opentest4j.AssertionFailedError: Expected org.jsoup.helper.ValidationException to be thrown, but nothing was thrown.
	at org.jsoup.helper.HttpConnectionTest.inputStream(HttpConnectionTest.java:256)
[INFO] BUILD FAILURE

After the fix:

$ mvn test -Dtest=HttpConnectionTest
[INFO] Running org.jsoup.helper.HttpConnectionTest
[INFO] Tests run: 42, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS

AI assistance disclosure

This contribution was produced with the help of an AI pipeline. The pipeline processed a large amount of source code to surface suspected bugs, reproduced a subset of them with failing unit tests and generated candidate fixes, and prepared pull requests from the ones that held up. Each PR was then reviewed and verified by a human before being opened: the fix and test were checked by hand and the test was confirmed to fail before the change and pass after.

KeyVal.inputStream(InputStream) validated the value field instead of the
inputStream argument, so inputStream(null) was not rejected (and a KeyVal with
a null value would fail with a misleading message). Validate the argument that
is actually used.
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.

1 participant