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

fix: use %s instead of %d format specifier in checkArgument #163

Merged
merged 2 commits into from
Mar 9, 2020

Conversation

athakor
Copy link
Contributor

@athakor athakor commented Mar 4, 2020

Fixes #159

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 4, 2020
@athakor athakor requested review from frankyn and JesseLovelace March 4, 2020 11:35
@codecov
Copy link

codecov bot commented Mar 4, 2020

Codecov Report

Merging #163 into master will increase coverage by 0.06%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #163      +/-   ##
============================================
+ Coverage     63.40%   63.46%   +0.06%     
  Complexity      537      537              
============================================
  Files            30       30              
  Lines          4752     4752              
  Branches        427      427              
============================================
+ Hits           3013     3016       +3     
+ Misses         1579     1576       -3     
  Partials        160      160              
Impacted Files Coverage Δ Complexity Δ
...om/google/cloud/storage/spi/v1/HttpStorageRpc.java 1.63% <0.00%> (ø) 1.00 <0.00> (ø)
...gle/cloud/storage/testing/RemoteStorageHelper.java 64.46% <0.00%> (+2.47%) 9.00% <0.00%> (ø%)

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 960572f...ea00cd5. Read the comment docs.

@@ -689,7 +689,7 @@ public long read(
Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_READ);
Scope scope = tracer.withSpan(span);
try {
checkArgument(position >= 0, "Position should be non-negative, is %d", position);
checkArgument(position >= 0, "Position should be non-negative, is %s", position);
Copy link
Contributor

Choose a reason for hiding this comment

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

I can't tell the difference between these two. %d looks correct to me. How about we use string concatenation with a plus sign here instead to avoid the issue.

I do notice this should probably not be inside the try block.

Choose a reason for hiding this comment

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

%d had been correct with standard formater, but is incorrect when using guava's Precondition library formatting. (You can check documentation and code linked in the associated issue)

Copy link
Contributor

Choose a reason for hiding this comment

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

The mere fact that we have to check documentation and that this is not obvious strongly suggests that we shouldn't use a format string at all. Just use string concatenation and call it a day.

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. I have used string concatenation + instead of %s. @elharo PTAL

@athakor athakor merged commit ee16197 into googleapis:master Mar 9, 2020
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.

Using %d instead of %s for formating in checkArgument
4 participants