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 some problems reported by PVS-Studio #7738

Merged
merged 2 commits into from
May 29, 2019
Merged

Conversation

leventov
Copy link
Member

Mostly cosmetics and unused code, no real bugs here.

@leventov leventov mentioned this pull request May 23, 2019
@@ -274,7 +272,7 @@ private long getOffset(boolean earliest) throws InterruptedException
}
}

return response != null ? filterAndDecode(response.messageSet(topic, partitionId), offset) : EMPTY_MSGS;
return filterAndDecode(response.messageSet(topic, partitionId), offset);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it impossible for response to be null at this point? I guess the idea is that if it's null, errorCode should be ErrorMapping.UnknownCode(), and therefore needNewLeader should be true, and so we should hit the continue; and keep looping.

The logic is a bit nontrivial to follow, so if that is accurate, a comment or Preconditions.checkState would be helpful.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's impossible. Open this class in IntelliJ - its data flow analysis identifies that the condition is always true as well.

Related to #7780.

@@ -91,7 +91,7 @@ public CoordinatorBasicAuthenticatorMetadataStorageUpdater(
BasicAuthCommonCacheConfig commonCacheConfig,
@Smile ObjectMapper objectMapper,
BasicAuthenticatorCacheNotifier cacheNotifier,
ConfigManager configManager // ConfigManager creates the db table we need, set a dependency here
ConfigManager configManager // -V6022: ConfigManager creates the db table we need, set a dependency here
Copy link
Contributor

Choose a reason for hiding this comment

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

What does -V6022 mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

It means an unused parameter. I've extended the comment.

@@ -52,7 +52,7 @@ public void kill(DataSegment segment) throws SegmentLoadingException
Map<String, Object> loadSpec = segment.getLoadSpec();
final String bucket = MapUtils.getString(loadSpec, "bucket");
final String indexPath = MapUtils.getString(loadSpec, "path");
final String descriptorPath = indexPath.substring(0, indexPath.lastIndexOf('/')) + "/descriptor.json";
final String descriptorPath = indexPath.substring(0, indexPath.lastIndexOf('/')) + "/descriptor.json"; //-V6009
Copy link
Contributor

Choose a reason for hiding this comment

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

What does -V6009 mean?

Copy link
Member Author

Choose a reason for hiding this comment

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

Refactored code to avoid the warning in the first place

Copy link
Member Author

Choose a reason for hiding this comment

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

This inspection means "substring() argument can be negative".

@@ -419,7 +419,7 @@ protected void mergeInsert(final int mergeAt, int insertAt, final float v, final
// use unused slot to shift array left or right and make space for the new bin to insert
if (insertAt < unusedIndex) {
shiftRight(insertAt, unusedIndex);
} else if (insertAt >= unusedIndex) {
} else { // insertAt >= unusedIndex
Copy link
Contributor

Choose a reason for hiding this comment

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

How about turning this into an assert instead of a comment (or just delete it, it's pretty obvious just from reading the code).

Copy link
Member Author

Choose a reason for hiding this comment

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

Deleted

@@ -241,6 +241,7 @@ public HttpResponseStatus getProxiedOverlordScalingResponseStatus()
);
}

@SuppressWarnings("unused") // It's unclear whether this call to readValue() has desirable side effects.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it has any meaningful side effects. response.getContent() is a string that's already been read, so it doesn't trigger reading a stream or anything like that. Should be fine to remove.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed

clintropolis added a commit that referenced this pull request May 23, 2019
from #7738, this is a performance issue
fjy pushed a commit that referenced this pull request May 23, 2019
from #7738, this is a performance issue
Copy link
Contributor

@gianm gianm left a comment

Choose a reason for hiding this comment

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

LGTM

@gianm gianm merged commit 782863e into apache:master May 29, 2019
@leventov leventov deleted the pvs-studio-2 branch May 30, 2019 15:39
@leventov
Copy link
Member Author

Thanks for review

jihoonson pushed a commit to implydata/druid-public that referenced this pull request Jun 4, 2019
jihoonson pushed a commit to implydata/druid-public that referenced this pull request Jun 26, 2019
* Fix some problems reported by PVS-Studio

* Address comments
gianm pushed a commit to implydata/druid-public that referenced this pull request Jul 4, 2019
* Fix some problems reported by PVS-Studio

* Address comments
@clintropolis clintropolis added this to the 0.16.0 milestone Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants