Skip to content

Throw IllegalArgumentException when jib.to.tags is set to a collection containing a null value. #2761

Merged
mpeddada1 merged 23 commits intomasterfrom
fix-npe
Sep 28, 2020
Merged

Throw IllegalArgumentException when jib.to.tags is set to a collection containing a null value. #2761
mpeddada1 merged 23 commits intomasterfrom
fix-npe

Conversation

@mpeddada1
Copy link
Contributor

Fixes #2760

@mpeddada1 mpeddada1 requested a review from a team September 14, 2020 21:54
ConfigurationPropertyValidator.parseListProperty(
System.getProperty(PropertyNames.TO_TAGS)));
String property = System.getProperty(PropertyNames.TO_TAGS);
Set<String> tags =
Copy link
Member

Choose a reason for hiding this comment

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

For readability: I think maybe tags is confusing with the class member tags (this.tags). Perhaps use something that differentiates it? Personally I don't think this.tags should be used very often outside constructors.

ConfigurationPropertyValidator.parseListProperty(
System.getProperty(PropertyNames.TO_TAGS)))
: this.tags;
if (tags.stream().anyMatch(Strings::isNullOrEmpty)) {
Copy link
Member

Choose a reason for hiding this comment

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

should we handle whitespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh that didn't occur to me. Thanks!


// Testing scenario where jib.to.tags is set to a collection containing a null value.
HashSet<String> tags = new HashSet<String>();
tags.add(null);
Copy link
Member

Choose a reason for hiding this comment

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

if we fail on empty, we should probably add a test for empty as well

Copy link
Member

Choose a reason for hiding this comment

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

Also the case of getting tags from the system property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch!

Assert.assertEquals("some username", testJibExtension.getTo().getAuth().getUsername());
Assert.assertEquals("some password", testJibExtension.getTo().getAuth().getPassword());

// Testing scenario where jib.to.tags is set to a collection containing a null value.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just put this in a new test?


// Testing scenario where jib.to.tags is set to a collection containing a null value.
HashSet<String> tags = new HashSet<String>();
tags.add(null);
Copy link
Member

Choose a reason for hiding this comment

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

Also the case of getting tags from the system property.

to.setTags(tags);
});
testJibExtension.getTo().getTags();
Assert.fail("Expect this to fail");
Copy link
Member

Choose a reason for hiding this comment

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

Nit: if the message doesn't provide additional helpful information or details, just use Assert.fail().

And I think it's meaningful to move testJibExtension.to() out of the try-catch block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, having all the extra lines outside the try-catch makes sense. Thanks!

property != null
? ImmutableSet.copyOf(
ConfigurationPropertyValidator.parseListProperty(
System.getProperty(PropertyNames.TO_TAGS)))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
System.getProperty(PropertyNames.TO_TAGS)))
property))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done:)

loosebazooka
loosebazooka previously approved these changes Sep 19, 2020
@loosebazooka loosebazooka dismissed their stale review September 21, 2020 18:09

SetProvider#get has odd behavior for null values, we need to handle this

Copy link
Contributor Author

@mpeddada1 mpeddada1 left a comment

Choose a reason for hiding this comment

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

Added this issue to the CHANGELOG.

@mpeddada1 mpeddada1 merged commit bedfe05 into master Sep 28, 2020
@mpeddada1 mpeddada1 deleted the fix-npe branch September 28, 2020 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NullPointerException when jib.to.tags is set to Set<String> containing null

4 participants