Skip to content

Commit 43873e6

Browse files
committed
HBASE-27373 Fix new spotbugs warnings after upgrading spotbugs to 4.7.2 (apache#4787)
Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
1 parent c94ec54 commit 43873e6

31 files changed

Lines changed: 114 additions & 203 deletions

File tree

hbase-client/src/main/java/org/apache/hadoop/hbase/exceptions/ClientExceptionsUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.apache.hadoop.hbase.exceptions;
1919

20+
import com.google.errorprone.annotations.RestrictedApi;
2021
import java.io.EOFException;
2122
import java.io.IOException;
2223
import java.io.SyncFailedException;
@@ -140,6 +141,10 @@ public static boolean isCallDroppedException(Throwable t) {
140141
* For test only. Usually you should use the {@link #isConnectionException(Throwable)} method
141142
* below.
142143
*/
144+
@RestrictedApi(explanation = "Should only be called in tests", link = "",
145+
allowedOnPath = ".*/src/test/.*")
146+
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
147+
justification = "test only")
143148
public static Set<Class<? extends Throwable>> getConnectionExceptionTypes() {
144149
return CONNECTION_EXCEPTION_TYPES;
145150
}

hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,18 +1473,12 @@ public static ServerInfo getServerInfo(final RpcController controller,
14731473
}
14741474
}
14751475

1476-
/**
1477-
* @see #buildGetServerInfoRequest()
1478-
*/
1479-
private static GetServerInfoRequest GET_SERVER_INFO_REQUEST =
1480-
GetServerInfoRequest.newBuilder().build();
1481-
14821476
/**
14831477
* Create a new GetServerInfoRequest
14841478
* @return a GetServerInfoRequest
14851479
*/
14861480
public static GetServerInfoRequest buildGetServerInfoRequest() {
1487-
return GET_SERVER_INFO_REQUEST;
1481+
return GetServerInfoRequest.getDefaultInstance();
14881482
}
14891483

14901484
public static ScanMetrics toScanMetrics(final byte[] bytes) {

hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/RequestConverter.java

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,32 +1032,20 @@ public static CompactRegionRequest buildCompactRegionRequest(byte[] regionName,
10321032
return builder.build();
10331033
}
10341034

1035-
/**
1036-
* @see #buildRollWALWriterRequest()
1037-
*/
1038-
private static RollWALWriterRequest ROLL_WAL_WRITER_REQUEST =
1039-
RollWALWriterRequest.newBuilder().build();
1040-
10411035
/**
10421036
* Create a new RollWALWriterRequest
10431037
* @return a ReplicateWALEntryRequest
10441038
*/
10451039
public static RollWALWriterRequest buildRollWALWriterRequest() {
1046-
return ROLL_WAL_WRITER_REQUEST;
1040+
return RollWALWriterRequest.getDefaultInstance();
10471041
}
10481042

1049-
/**
1050-
* @see #buildGetServerInfoRequest()
1051-
*/
1052-
private static GetServerInfoRequest GET_SERVER_INFO_REQUEST =
1053-
GetServerInfoRequest.newBuilder().build();
1054-
10551043
/**
10561044
* Create a new GetServerInfoRequest
10571045
* @return a GetServerInfoRequest
10581046
*/
10591047
public static GetServerInfoRequest buildGetServerInfoRequest() {
1060-
return GET_SERVER_INFO_REQUEST;
1048+
return GetServerInfoRequest.getDefaultInstance();
10611049
}
10621050

10631051
/**
@@ -1438,18 +1426,12 @@ public static GetClusterStatusRequest buildGetClusterStatusRequest(EnumSet<Optio
14381426
.addAllOptions(ClusterMetricsBuilder.toOptions(options)).build();
14391427
}
14401428

1441-
/**
1442-
* @see #buildCatalogScanRequest
1443-
*/
1444-
private static final RunCatalogScanRequest CATALOG_SCAN_REQUEST =
1445-
RunCatalogScanRequest.newBuilder().build();
1446-
14471429
/**
14481430
* Creates a request for running a catalog scan
14491431
* @return A {@link RunCatalogScanRequest}
14501432
*/
14511433
public static RunCatalogScanRequest buildCatalogScanRequest() {
1452-
return CATALOG_SCAN_REQUEST;
1434+
return RunCatalogScanRequest.getDefaultInstance();
14531435
}
14541436

14551437
/**
@@ -1460,32 +1442,20 @@ public static EnableCatalogJanitorRequest buildEnableCatalogJanitorRequest(boole
14601442
return EnableCatalogJanitorRequest.newBuilder().setEnable(enable).build();
14611443
}
14621444

1463-
/**
1464-
* @see #buildIsCatalogJanitorEnabledRequest()
1465-
*/
1466-
private static final IsCatalogJanitorEnabledRequest IS_CATALOG_JANITOR_ENABLED_REQUEST =
1467-
IsCatalogJanitorEnabledRequest.newBuilder().build();
1468-
14691445
/**
14701446
* Creates a request for querying the master whether the catalog janitor is enabled
14711447
* @return A {@link IsCatalogJanitorEnabledRequest}
14721448
*/
14731449
public static IsCatalogJanitorEnabledRequest buildIsCatalogJanitorEnabledRequest() {
1474-
return IS_CATALOG_JANITOR_ENABLED_REQUEST;
1450+
return IsCatalogJanitorEnabledRequest.getDefaultInstance();
14751451
}
14761452

1477-
/**
1478-
* @see #buildRunCleanerChoreRequest()
1479-
*/
1480-
private static final RunCleanerChoreRequest CLEANER_CHORE_REQUEST =
1481-
RunCleanerChoreRequest.newBuilder().build();
1482-
14831453
/**
14841454
* Creates a request for running cleaner chore
14851455
* @return A {@link RunCleanerChoreRequest}
14861456
*/
14871457
public static RunCleanerChoreRequest buildRunCleanerChoreRequest() {
1488-
return CLEANER_CHORE_REQUEST;
1458+
return RunCleanerChoreRequest.getDefaultInstance();
14891459
}
14901460

14911461
/**
@@ -1496,18 +1466,12 @@ public static SetCleanerChoreRunningRequest buildSetCleanerChoreRunningRequest(b
14961466
return SetCleanerChoreRunningRequest.newBuilder().setOn(on).build();
14971467
}
14981468

1499-
/**
1500-
* @see #buildIsCleanerChoreEnabledRequest()
1501-
*/
1502-
private static final IsCleanerChoreEnabledRequest IS_CLEANER_CHORE_ENABLED_REQUEST =
1503-
IsCleanerChoreEnabledRequest.newBuilder().build();
1504-
15051469
/**
15061470
* Creates a request for querying the master whether the cleaner chore is enabled
15071471
* @return A {@link IsCleanerChoreEnabledRequest}
15081472
*/
15091473
public static IsCleanerChoreEnabledRequest buildIsCleanerChoreEnabledRequest() {
1510-
return IS_CLEANER_CHORE_ENABLED_REQUEST;
1474+
return IsCleanerChoreEnabledRequest.getDefaultInstance();
15111475
}
15121476

15131477
/**
@@ -1727,34 +1691,25 @@ public static ClearCompactionQueuesRequest buildClearCompactionQueuesRequest(Set
17271691
return builder.build();
17281692
}
17291693

1730-
private static final GetSpaceQuotaRegionSizesRequest GET_SPACE_QUOTA_REGION_SIZES_REQUEST =
1731-
GetSpaceQuotaRegionSizesRequest.newBuilder().build();
1732-
17331694
/**
17341695
* Returns a {@link GetSpaceQuotaRegionSizesRequest} object.
17351696
*/
17361697
public static GetSpaceQuotaRegionSizesRequest buildGetSpaceQuotaRegionSizesRequest() {
1737-
return GET_SPACE_QUOTA_REGION_SIZES_REQUEST;
1698+
return GetSpaceQuotaRegionSizesRequest.getDefaultInstance();
17381699
}
17391700

1740-
private static final GetSpaceQuotaSnapshotsRequest GET_SPACE_QUOTA_SNAPSHOTS_REQUEST =
1741-
GetSpaceQuotaSnapshotsRequest.newBuilder().build();
1742-
17431701
/**
17441702
* Returns a {@link GetSpaceQuotaSnapshotsRequest} object.
17451703
*/
17461704
public static GetSpaceQuotaSnapshotsRequest buildGetSpaceQuotaSnapshotsRequest() {
1747-
return GET_SPACE_QUOTA_SNAPSHOTS_REQUEST;
1705+
return GetSpaceQuotaSnapshotsRequest.getDefaultInstance();
17481706
}
17491707

1750-
private static final GetQuotaStatesRequest GET_QUOTA_STATES_REQUEST =
1751-
GetQuotaStatesRequest.newBuilder().build();
1752-
17531708
/**
17541709
* Returns a {@link GetQuotaStatesRequest} object.
17551710
*/
17561711
public static GetQuotaStatesRequest buildGetQuotaStatesRequest() {
1757-
return GET_QUOTA_STATES_REQUEST;
1712+
return GetQuotaStatesRequest.getDefaultInstance();
17581713
}
17591714

17601715
public static DecommissionRegionServersRequest

hbase-common/src/main/java/org/apache/hadoop/hbase/io/crypto/CryptoCipherProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public final class CryptoCipherProvider implements CipherProvider {
3030

3131
private static CryptoCipherProvider instance;
3232

33+
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
34+
justification = "singleton pattern")
3335
public static CryptoCipherProvider getInstance() {
3436
if (instance != null) {
3537
return instance;

hbase-common/src/main/java/org/apache/hadoop/hbase/io/crypto/DefaultCipherProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public final class DefaultCipherProvider implements CipherProvider {
3030

3131
private static DefaultCipherProvider instance;
3232

33+
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
34+
justification = "singleton pattern")
3335
public static DefaultCipherProvider getInstance() {
3436
if (instance != null) {
3537
return instance;

hbase-common/src/main/java/org/apache/hadoop/hbase/security/Superusers.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
import java.io.IOException;
2121
import java.util.Collection;
22-
import java.util.HashSet;
23-
import java.util.Set;
2422
import org.apache.hadoop.conf.Configuration;
2523
import org.apache.hadoop.hbase.AuthUtil;
2624
import org.apache.yetus.audience.InterfaceAudience;
2725
import org.slf4j.Logger;
2826
import org.slf4j.LoggerFactory;
2927

28+
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableSet;
29+
3030
/**
3131
* Keeps lists of superusers and super groups loaded from HBase configuration, checks if certain
3232
* user is regarded as superuser.
@@ -38,8 +38,8 @@ public final class Superusers {
3838
/** Configuration key for superusers */
3939
public static final String SUPERUSER_CONF_KEY = "hbase.superuser"; // Not getting a name
4040

41-
private static Set<String> superUsers;
42-
private static Set<String> superGroups;
41+
private static ImmutableSet<String> superUsers;
42+
private static ImmutableSet<String> superGroups;
4343
private static User systemUser;
4444

4545
private Superusers() {
@@ -53,8 +53,8 @@ private Superusers() {
5353
* @throws IllegalStateException if current user is null
5454
*/
5555
public static void initialize(Configuration conf) throws IOException {
56-
superUsers = new HashSet<>();
57-
superGroups = new HashSet<>();
56+
ImmutableSet.Builder<String> superUsersBuilder = ImmutableSet.builder();
57+
ImmutableSet.Builder<String> superGroupsBuilder = ImmutableSet.builder();
5858
systemUser = User.getCurrent();
5959

6060
if (systemUser == null) {
@@ -64,17 +64,19 @@ public static void initialize(Configuration conf) throws IOException {
6464

6565
String currentUser = systemUser.getShortName();
6666
LOG.trace("Current user name is {}", currentUser);
67-
superUsers.add(currentUser);
67+
superUsersBuilder.add(currentUser);
6868

6969
String[] superUserList = conf.getStrings(SUPERUSER_CONF_KEY, new String[0]);
7070
for (String name : superUserList) {
7171
if (AuthUtil.isGroupPrincipal(name)) {
7272
// Let's keep the '@' for distinguishing from user.
73-
superGroups.add(name);
73+
superGroupsBuilder.add(name);
7474
} else {
75-
superUsers.add(name);
75+
superUsersBuilder.add(name);
7676
}
7777
}
78+
superUsers = superUsersBuilder.build();
79+
superGroups = superGroupsBuilder.build();
7880
}
7981

8082
/**
@@ -111,14 +113,20 @@ public static boolean isSuperUser(String user) {
111113
return superUsers.contains(user) || superGroups.contains(user);
112114
}
113115

116+
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
117+
justification = "immutable")
114118
public static Collection<String> getSuperUsers() {
115119
return superUsers;
116120
}
117121

122+
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
123+
justification = "immutable")
118124
public static Collection<String> getSuperGroups() {
119125
return superGroups;
120126
}
121127

128+
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
129+
justification = "by design")
122130
public static User getSystemUser() {
123131
return systemUser;
124132
}

hbase-metrics/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@
7676
<groupId>io.dropwizard.metrics</groupId>
7777
<artifactId>metrics-core</artifactId>
7878
</dependency>
79+
<dependency>
80+
<groupId>com.github.stephenc.findbugs</groupId>
81+
<artifactId>findbugs-annotations</artifactId>
82+
<scope>compile</scope>
83+
<optional>true</optional>
84+
</dependency>
7985
<dependency>
8086
<groupId>junit</groupId>
8187
<artifactId>junit</artifactId>

hbase-metrics/src/main/java/org/apache/hadoop/hbase/metrics/impl/FastLongHistogram.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ public void add(long value, long count) {
138138
/**
139139
* Computes the quantiles give the ratios.
140140
*/
141+
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "FL_FLOATS_AS_LOOP_COUNTERS",
142+
justification = "valid usage")
141143
public long[] getQuantiles(double[] quantiles) {
142144
if (!hasData) {
143145
// No data yet.
@@ -266,10 +268,6 @@ public FastLongHistogram(int numOfBins, long min, long max) {
266268
this.bins = new Bins(bins, numOfBins, 0.01, 0.999);
267269
}
268270

269-
private FastLongHistogram(Bins bins) {
270-
this.bins = bins;
271-
}
272-
273271
/**
274272
* Adds a value to the histogram.
275273
*/

hbase-protocol/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
<groupId>org.slf4j</groupId>
4343
<artifactId>slf4j-api</artifactId>
4444
</dependency>
45+
<dependency>
46+
<groupId>com.github.stephenc.findbugs</groupId>
47+
<artifactId>findbugs-annotations</artifactId>
48+
<scope>compile</scope>
49+
<optional>true</optional>
50+
</dependency>
4551
</dependencies>
4652
<build>
4753
<plugins>

hbase-protocol/src/main/java/com/google/protobuf/HBaseZeroCopyByteString.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public static ByteString wrap(final byte[] array, int offset, int length) {
6565
* of a {@code LiteralByteString}.
6666
* @return byte[] representation
6767
*/
68+
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
69+
justification = "by design")
6870
public static byte[] zeroCopyGetBytes(final ByteString buf) {
6971
if (buf instanceof LiteralByteString) {
7072
return ((LiteralByteString) buf).bytes;

0 commit comments

Comments
 (0)