Skip to content

HIVE-28888: Fix spotbugs issues in hive-storage-api and hive-service-rpc with spotbugs-maven-plugin 4.8.6.6 #5754

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

tanishq-chugh
Copy link
Contributor

@tanishq-chugh tanishq-chugh commented Apr 8, 2025

What changes were proposed in this pull request?

Upgrade spotbugs-maven-plugin to 4.8.6.6

Why are the changes needed?

Upgraded plugin introduces new rules to identify potential bugs.

Does this PR introduce any user-facing change?

No

Is the change a dependency upgrade?

No, it is a plugin version upgrade.

How was this patch tested?

Locally, running spotbugs check and fixing the bugs, followed by running basic manual test on hive by building locally and running queries.

public static ValidReadTxnList fromValue(String value) {
ValidReadTxnList txnList = new ValidReadTxnList();
txnList.readFromString(value);
return txnList;
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is for CT_CONSTRUCTOR_THROW, as far as I tested it locally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this change is as well to address CT_CONSTRUCTOR_THROW spotbug.

Jenkinsfile Outdated
@@ -267,7 +264,7 @@ if [ $n != 0 ]; then
exit 1
fi
'''
buildHive("-Pspotbugs -pl " + spotbugsProjects.join(",") + " -am test-compile com.github.spotbugs:spotbugs-maven-plugin:4.0.0:check")
buildHive("-Pspotbugs -pl " + spotbugsProjects.join(",") + " -am test-compile com.github.spotbugs:spotbugs-maven-plugin:4.8.6.6:check")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
buildHive("-Pspotbugs -pl " + spotbugsProjects.join(",") + " -am test-compile com.github.spotbugs:spotbugs-maven-plugin:4.8.6.6:check")
buildHive("-Pspotbugs -pl " + spotbugsProjects.join(",") + " -am test-compile com.github.spotbugs:spotbugs-maven-plugin:4.8.6.6:check")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out, made this change in be7e285

Jenkinsfile Outdated
Comment on lines 254 to 255
":hive-storage-api",
":hive-service-rpc"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
":hive-storage-api",
":hive-service-rpc"
":hive-storage-api",
":hive-service-rpc"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out as well, made this change in be7e285

@@ -329,20 +331,19 @@ public static void mergeBloomFilterBytes(
* for index bounds nor expand the bit set size if the specified index is greater than the size.
*/
static class BitSet {
private final long[] data;
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we can keep this final. The new Spot bugs fail if the constructor might fail. If it never fails, it is ok.

// make it private
private BitSet(long[] data) {
  this.data = data; // without assert here
}

public static BitSet build(long[] data) {
  assert data.length > 0 : "data length is zero!";
  return new BitSet(data);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. This is definitely a better approach to solve this spotbug. Thanks for the suggestion. i have made the change in be7e285

@@ -59,32 +60,44 @@ private static void checkArgument(boolean expression, String message) {
}
}

public BloomKFilter(long maxNumEntries) {
public BloomKFilter(int k, long m, int totalBlockCount, long[] arr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public BloomKFilter(int k, long m, int totalBlockCount, long[] arr) {
private BloomKFilter(int k, long m, int totalBlockCount, long[] arr) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made it private in be7e285

@@ -397,21 +410,14 @@ public static byte[] getInitialBytes(long expectedEntries) {
* for index bounds nor expand the bit set size if the specified index is greater than the size.
*/
public static class BitSet {
private final long[] data;
private long[] data;
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be final maybe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Made the field private as well as changed the constructor/build method similar to your suggested change for BloomFilter Bitset class. Change made in be7e285

@okumin
Copy link
Contributor

okumin commented Apr 16, 2025

Thanks. From my point of view, we'll have to do the following things when we close this pull request.

  • We have to include the JIRA ticket id in the PR title(= commit message)
  • We have to close the linked JIRA ticket with fix version = 4.1.0

I assume this PR includes HIVE-28888, HIVE-28889 and HIVE-28893. I expect the remaining tickets, meaning HIVE-28890, HIVE-28891, and HIVE-28892, not to be included.

I am thinking of consolidating tickets like below, keeping 1-1 mapping between PR and JIRA[1].

Also, I added some minor comments. I ran spot bugs on my local machine with this change, and I've not seen any issues so far. Thanks!

  • [1] I've seen the case PR : JIRA = 1 : N but I don't know when we should accept it

@tanishq-chugh tanishq-chugh changed the title HIVE-28887: Fix spotbugs issues in hive-storage-api and hive-service-rpc with spotbugs-maven-plugin 4.8.6.6 HIVE-28888: Fix spotbugs issues in hive-storage-api and hive-service-rpc with spotbugs-maven-plugin 4.8.6.6 Apr 16, 2025
@tanishq-chugh
Copy link
Contributor Author

@okumin
Yes, that absolutely makes sense. I have changed the PR title to include the JIRA - HIVE-28888, with which we can go ahead as you mentioned. We'll make sure the upcoming PRs for this initiative have a 1:1 JIRA PR mapping.
Thank you!

Copy link
Contributor

@okumin okumin left a comment

Choose a reason for hiding this comment

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

@tanishq-chugh Thank you! Only one point. Could you please remove the unused import, import java.util.BitSet;? SonarCloud reported the issue.
I speculatively give this PR +1. I will merge it once the code style issue is resolved and also CI succeeds.

@@ -26,6 +26,7 @@
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.BitSet;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import java.util.BitSet;

It looks like this is not used.
https://sonarcloud.io/project/issues?pullRequest=5754&open=AZYgu6tSMQfuFZWXHEBO&id=apache_hive

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been addressed in 3ab7cae

this.totalBlockCount = bitSet.data.length / DEFAULT_BLOCK_SIZE;
}
public static BloomKFilter build(long[] bits, int numFuncs) {
checkArgument((bits.length % DEFAULT_BLOCK_SIZE) == 0, "bitSet has to be block aligned");
return new BloomKFilter(bits,numFuncs);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return new BloomKFilter(bits,numFuncs);
return new BloomKFilter(bits, numFuncs);

Just align the style with other lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been addressed in 3ab7cae

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants