Skip to content

Commit 150a80f

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 df5c1ca commit 150a80f

File tree

32 files changed

+114
-207
lines changed

32 files changed

+114
-207
lines changed

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;
@@ -120,6 +121,10 @@ public static Throwable findException(Object exception) {
120121
* For test only. Usually you should use the {@link #isConnectionException(Throwable)} method
121122
* below.
122123
*/
124+
@RestrictedApi(explanation = "Should only be called in tests", link = "",
125+
allowedOnPath = ".*/src/test/.*")
126+
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
127+
justification = "test only")
123128
public static Set<Class<? extends Throwable>> getConnectionExceptionTypes() {
124129
return CONNECTION_EXCEPTION_TYPES;
125130
}

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
@@ -1475,18 +1475,12 @@ public static ServerInfo getServerInfo(final RpcController controller,
14751475
}
14761476
}
14771477

1478-
/**
1479-
* @see #buildGetServerInfoRequest()
1480-
*/
1481-
private static GetServerInfoRequest GET_SERVER_INFO_REQUEST =
1482-
GetServerInfoRequest.newBuilder().build();
1483-
14841478
/**
14851479
* Create a new GetServerInfoRequest
14861480
* @return a GetServerInfoRequest
14871481
*/
14881482
public static GetServerInfoRequest buildGetServerInfoRequest() {
1489-
return GET_SERVER_INFO_REQUEST;
1483+
return GetServerInfoRequest.getDefaultInstance();
14901484
}
14911485

14921486
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
@@ -1035,32 +1035,20 @@ public static CompactRegionRequest buildCompactRegionRequest(byte[] regionName,
10351035
return builder.build();
10361036
}
10371037

1038-
/**
1039-
* @see #buildRollWALWriterRequest()
1040-
*/
1041-
private static RollWALWriterRequest ROLL_WAL_WRITER_REQUEST =
1042-
RollWALWriterRequest.newBuilder().build();
1043-
10441038
/**
10451039
* Create a new RollWALWriterRequest
10461040
* @return a ReplicateWALEntryRequest
10471041
*/
10481042
public static RollWALWriterRequest buildRollWALWriterRequest() {
1049-
return ROLL_WAL_WRITER_REQUEST;
1043+
return RollWALWriterRequest.getDefaultInstance();
10501044
}
10511045

1052-
/**
1053-
* @see #buildGetServerInfoRequest()
1054-
*/
1055-
private static GetServerInfoRequest GET_SERVER_INFO_REQUEST =
1056-
GetServerInfoRequest.newBuilder().build();
1057-
10581046
/**
10591047
* Create a new GetServerInfoRequest
10601048
* @return a GetServerInfoRequest
10611049
*/
10621050
public static GetServerInfoRequest buildGetServerInfoRequest() {
1063-
return GET_SERVER_INFO_REQUEST;
1051+
return GetServerInfoRequest.getDefaultInstance();
10641052
}
10651053

10661054
/**
@@ -1457,18 +1445,12 @@ public static GetClusterStatusRequest buildGetClusterStatusRequest(EnumSet<Optio
14571445
.addAllOptions(ClusterMetricsBuilder.toOptions(options)).build();
14581446
}
14591447

1460-
/**
1461-
* @see #buildCatalogScanRequest
1462-
*/
1463-
private static final RunCatalogScanRequest CATALOG_SCAN_REQUEST =
1464-
RunCatalogScanRequest.newBuilder().build();
1465-
14661448
/**
14671449
* Creates a request for running a catalog scan
14681450
* @return A {@link RunCatalogScanRequest}
14691451
*/
14701452
public static RunCatalogScanRequest buildCatalogScanRequest() {
1471-
return CATALOG_SCAN_REQUEST;
1453+
return RunCatalogScanRequest.getDefaultInstance();
14721454
}
14731455

14741456
/**
@@ -1479,32 +1461,20 @@ public static EnableCatalogJanitorRequest buildEnableCatalogJanitorRequest(boole
14791461
return EnableCatalogJanitorRequest.newBuilder().setEnable(enable).build();
14801462
}
14811463

1482-
/**
1483-
* @see #buildIsCatalogJanitorEnabledRequest()
1484-
*/
1485-
private static final IsCatalogJanitorEnabledRequest IS_CATALOG_JANITOR_ENABLED_REQUEST =
1486-
IsCatalogJanitorEnabledRequest.newBuilder().build();
1487-
14881464
/**
14891465
* Creates a request for querying the master whether the catalog janitor is enabled
14901466
* @return A {@link IsCatalogJanitorEnabledRequest}
14911467
*/
14921468
public static IsCatalogJanitorEnabledRequest buildIsCatalogJanitorEnabledRequest() {
1493-
return IS_CATALOG_JANITOR_ENABLED_REQUEST;
1469+
return IsCatalogJanitorEnabledRequest.getDefaultInstance();
14941470
}
14951471

1496-
/**
1497-
* @see #buildRunCleanerChoreRequest()
1498-
*/
1499-
private static final RunCleanerChoreRequest CLEANER_CHORE_REQUEST =
1500-
RunCleanerChoreRequest.newBuilder().build();
1501-
15021472
/**
15031473
* Creates a request for running cleaner chore
15041474
* @return A {@link RunCleanerChoreRequest}
15051475
*/
15061476
public static RunCleanerChoreRequest buildRunCleanerChoreRequest() {
1507-
return CLEANER_CHORE_REQUEST;
1477+
return RunCleanerChoreRequest.getDefaultInstance();
15081478
}
15091479

15101480
/**
@@ -1515,18 +1485,12 @@ public static SetCleanerChoreRunningRequest buildSetCleanerChoreRunningRequest(b
15151485
return SetCleanerChoreRunningRequest.newBuilder().setOn(on).build();
15161486
}
15171487

1518-
/**
1519-
* @see #buildIsCleanerChoreEnabledRequest()
1520-
*/
1521-
private static final IsCleanerChoreEnabledRequest IS_CLEANER_CHORE_ENABLED_REQUEST =
1522-
IsCleanerChoreEnabledRequest.newBuilder().build();
1523-
15241488
/**
15251489
* Creates a request for querying the master whether the cleaner chore is enabled
15261490
* @return A {@link IsCleanerChoreEnabledRequest}
15271491
*/
15281492
public static IsCleanerChoreEnabledRequest buildIsCleanerChoreEnabledRequest() {
1529-
return IS_CLEANER_CHORE_ENABLED_REQUEST;
1493+
return IsCleanerChoreEnabledRequest.getDefaultInstance();
15301494
}
15311495

15321496
/**
@@ -1746,34 +1710,25 @@ public static ClearCompactionQueuesRequest buildClearCompactionQueuesRequest(Set
17461710
return builder.build();
17471711
}
17481712

1749-
private static final GetSpaceQuotaRegionSizesRequest GET_SPACE_QUOTA_REGION_SIZES_REQUEST =
1750-
GetSpaceQuotaRegionSizesRequest.newBuilder().build();
1751-
17521713
/**
17531714
* Returns a {@link GetSpaceQuotaRegionSizesRequest} object.
17541715
*/
17551716
public static GetSpaceQuotaRegionSizesRequest buildGetSpaceQuotaRegionSizesRequest() {
1756-
return GET_SPACE_QUOTA_REGION_SIZES_REQUEST;
1717+
return GetSpaceQuotaRegionSizesRequest.getDefaultInstance();
17571718
}
17581719

1759-
private static final GetSpaceQuotaSnapshotsRequest GET_SPACE_QUOTA_SNAPSHOTS_REQUEST =
1760-
GetSpaceQuotaSnapshotsRequest.newBuilder().build();
1761-
17621720
/**
17631721
* Returns a {@link GetSpaceQuotaSnapshotsRequest} object.
17641722
*/
17651723
public static GetSpaceQuotaSnapshotsRequest buildGetSpaceQuotaSnapshotsRequest() {
1766-
return GET_SPACE_QUOTA_SNAPSHOTS_REQUEST;
1724+
return GetSpaceQuotaSnapshotsRequest.getDefaultInstance();
17671725
}
17681726

1769-
private static final GetQuotaStatesRequest GET_QUOTA_STATES_REQUEST =
1770-
GetQuotaStatesRequest.newBuilder().build();
1771-
17721727
/**
17731728
* Returns a {@link GetQuotaStatesRequest} object.
17741729
*/
17751730
public static GetQuotaStatesRequest buildGetQuotaStatesRequest() {
1776-
return GET_QUOTA_STATES_REQUEST;
1731+
return GetQuotaStatesRequest.getDefaultInstance();
17771732
}
17781733

17791734
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/io/util/BlockIOUtils.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,6 @@ private static boolean preadWithExtraDirectly(ByteBuff buff, FSDataInputStream d
367367
} catch (InvocationTargetException e) {
368368
throw new IOException("Encountered an exception when invoking ByteBuffer positioned read"
369369
+ " when trying to read " + bytesRead + " bytes from position " + position, e);
370-
} catch (NullPointerException e) {
371-
throw new IOException("something is null");
372-
} catch (Exception e) {
373-
throw e;
374370
}
375371
if (ret < 0) {
376372
throw new IOException("Premature EOF from inputStream (positional read returned " + ret

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
/**
@@ -113,14 +115,20 @@ public static boolean isSuperUser(String user) {
113115
return superUsers.contains(user) || superGroups.contains(user);
114116
}
115117

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

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

130+
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
131+
justification = "by design")
124132
public static User getSystemUser() {
125133
return systemUser;
126134
}

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;

hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RESTServlet.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ UserGroupInformation getRealUser() {
5353
}
5454

5555
/** Returns the RESTServlet singleton instance */
56+
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
57+
justification = "singleton pattern")
5658
public synchronized static RESTServlet getInstance() {
5759
assert (INSTANCE != null);
5860
return INSTANCE;
@@ -66,8 +68,10 @@ public ConnectionCache getConnectionCache() {
6668
/**
6769
* @param conf Existing configuration to use in rest servlet
6870
* @param userProvider the login user provider
69-
* @return the RESTServlet singleton instance n
71+
* @return the RESTServlet singleton instance
7072
*/
73+
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "MS_EXPOSE_REP",
74+
justification = "singleton pattern")
7175
public synchronized static RESTServlet getInstance(Configuration conf, UserProvider userProvider)
7276
throws IOException {
7377
if (INSTANCE == null) {

0 commit comments

Comments
 (0)