Avoid NPE when combined location strategy sub strategies is immutable…#639
Conversation
|
|
| final Collection<FileLocationStrategy> collectionThatThrowsNPE = new ArrayList<FileLocationStrategy>(Arrays.asList(getSubStrategies())) { | ||
| @Override | ||
| public boolean contains(Object o) { | ||
| if (o == null) { |
There was a problem hiding this comment.
This is a test, use assertNotNull().
| @Override | ||
| public boolean contains(Object o) { | ||
| if (o == null) { | ||
| throw new NullPointerException("Collection does not support null"); |
There was a problem hiding this comment.
Use Objects.requireNonNull().
| // Create a collection that throws NPE on contains(null) like ImmutableList does | ||
| final Collection<FileLocationStrategy> collectionThatThrowsNPE = new ArrayList<FileLocationStrategy>(Arrays.asList(getSubStrategies())) { | ||
| @Override | ||
| public boolean contains(Object o) { |
| */ | ||
| @Test | ||
| void testInitCollectionThrowsNPEOnContainsNull() { | ||
| // Create a collection that throws NPE on contains(null) like ImmutableList does |
There was a problem hiding this comment.
Whose ImmutableList? Don't you mean implementations like java.util.ImmutableCollections.List12.indexOf(Object)?
There was a problem hiding this comment.
Yes, I've slightly updated the comment.
You are correct, these Javadoc warning occur in generated code and we are ignoring them for now. |
|
Hello @weih-kahoot You MUST run TY! |
|
@garydgregory Sorry, I forgot that. I have pushed another commit to fix checkstyle errors(we should squash my commits before merging). |
I normally squash before a merge but that's something you can also do on your end. |
f33cfbf to
0733706
Compare
|
@garydgregory Okay, I've squashed my commits |
In our project, we use CombiendLocationStrategy(List.of(...)), this will result a NPE as List#contains will be called for the passed-in immutable list instance.
Thanks for your contribution to Apache Commons! Your help is appreciated!
Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.