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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -689,7 +689,7 @@ public Tuple<String, byte[]> 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

Get req = createReadRequest(from, options);
StringBuilder range = new StringBuilder();
range.append("bytes=").append(position).append("-").append(position + bytes - 1);
Expand Down