Skip to content

IO-665 ensure that passing a null InputStream results in NPE with tests#112

Merged
garydgregory merged 4 commits into
apache:masterfrom
ottobackwards:IO-665
Apr 14, 2020
Merged

IO-665 ensure that passing a null InputStream results in NPE with tests#112
garydgregory merged 4 commits into
apache:masterfrom
ottobackwards:IO-665

Conversation

@ottobackwards

@ottobackwards ottobackwards commented Apr 13, 2020

Copy link
Copy Markdown
Contributor

This pr adds a null check for the InputStream constructor of XmlStreamReader. This makes it so that each contractor of type ( File, URL, URLConnection, InputStream ) throws NPE if passed a NULL for that type.

Tests were added as well for each type.


This change is Reviewable

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could other constructors benefit from this check?

Comment thread src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java Outdated
@ottobackwards

Copy link
Copy Markdown
Contributor Author

The other contructors, already throw the NPE so I didn't change them. We could add the check to ensure that thread is always a message though.

@ottobackwards

Copy link
Copy Markdown
Contributor Author

Actually, since they use

this(object.somethingThatReturnsAStream()) we would have to change the initialization pattern from this() to some sort of initialize pattern.

Do you have a preference in that area?

They behave correctly, but there is no message.

@coveralls

coveralls commented Apr 13, 2020

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.1%) to 89.739% when pulling 2dcd21b on ottobackwards:IO-665 into 6a78ef8 on apache:master.

Comment thread src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
@garydgregory

Copy link
Copy Markdown
Member

Actually, since they use

this(object.somethingThatReturnsAStream()) we would have to change the initialization pattern from this() to some sort of initialize pattern.

Do you have a preference in that area?

They behave correctly, but there is no message.

I do not see why you'd need anything more than changing methods like:

    public XmlStreamReader(final URL url) throws IOException {
        this(url.openConnection(), null);
    }

to:

    public XmlStreamReader(final URL url) throws IOException {
        this(Objects.requireNonNull(url, "url").openConnection(), null);
    }

@ottobackwards

Copy link
Copy Markdown
Contributor Author

That is because you @garydgregory know java better than I lol. Will do

@ottobackwards

Copy link
Copy Markdown
Contributor Author

@garydgregory done

@garydgregory

Copy link
Copy Markdown
Member

That is because you @garydgregory know java better than I lol. Will do

;-)

@garydgregory garydgregory merged commit 2c13fc8 into apache:master Apr 14, 2020
brettlounsbury pushed a commit to brettlounsbury/commons-io that referenced this pull request May 28, 2020
…ts (apache#112)

* ensure that passing a null InputStream results in NPE with tests

* remove stray import from bad autocomplete

* per review, fix formating for lamda () ->

* per review, protect other constructors
brettlounsbury pushed a commit to brettlounsbury/commons-io that referenced this pull request May 28, 2020
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.

5 participants