Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage: Allow null values in labels map #6859

Merged
merged 5 commits into from Nov 22, 2019
Merged

Storage: Allow null values in labels map #6859

merged 5 commits into from Nov 22, 2019

Conversation

JesseLovelace
Copy link
Contributor

@JesseLovelace JesseLovelace commented Nov 21, 2019

The way to delete a label is to set its value in the labels map to null. Currently, the labels map is converted to an ImmutableMap, which can't have null values. It's still possible to delete values by setting their values to the empty string, but that's not intuitive, users would generally expect setting null to work based on the documentation. This converts null values to the empty string in the builder to accomplish this. This was discovered while updating Java samples

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 21, 2019
new Function<String, String>() {
@Override
public String apply(String input) {
return input == null ? "" : input;
Copy link
Member

Choose a reason for hiding this comment

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

For consistency could you use Data.<String>nullOf(String.class).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems obtuse to me, but I'll do it for consistency. Is there a reason it wouldn't be better/more readable to do it the other way around and replace other instances of Data.nullOf(String.class) with "" for readability?

Copy link
Member

Choose a reason for hiding this comment

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

Could you file an issue to better address this in the library for readability? So it's done all at once instead of a one-off and then we can maintain consistency for now.

@@ -1209,7 +1211,17 @@ public Builder setDefaultAcl(Iterable<Acl> acl) {

@Override
public Builder setLabels(Map<String, String> labels) {
this.labels = labels != null ? ImmutableMap.copyOf(labels) : null;
if (labels != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Add an integration test to exercise this case.

@codecov
Copy link

codecov bot commented Nov 22, 2019

Codecov Report

Merging #6859 into master will increase coverage by <.01%.
The diff coverage is 80%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #6859      +/-   ##
============================================
+ Coverage     46.37%   46.37%   +<.01%     
+ Complexity    28045    28029      -16     
============================================
  Files          2615     2615              
  Lines        288309   288313       +4     
  Branches      33804    33810       +6     
============================================
+ Hits         133712   133716       +4     
  Misses       144333   144333              
  Partials      10264    10264
Impacted Files Coverage Δ Complexity Δ
...main/java/com/google/cloud/storage/BucketInfo.java 83.3% <80%> (+0.11%) 84 <0> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ac6cd0b...b45964c. Read the comment docs.

@frankyn
Copy link
Member

frankyn commented Nov 22, 2019

I see you added a unit test. could you add an integration test as well? Overall LGTM.

Copy link
Member

@frankyn frankyn left a comment

Choose a reason for hiding this comment

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

Pending tests passing, otherwise LGTM. Thanks @JesseLovelace!

@JesseLovelace JesseLovelace merged commit e864ba3 into master Nov 22, 2019
@JesseLovelace JesseLovelace deleted the fixsetlabels branch November 22, 2019 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants