From 29a208e58ae7055d933c14127d319d9b05294dc0 Mon Sep 17 00:00:00 2001 From: Mike Drob Date: Thu, 14 Jun 2018 21:34:06 -0500 Subject: [PATCH] HBASE-20736 fix error-prone warnings --- hbase-build-configuration/pom.xml | 5 +- .../client/PreemptiveFastFailInterceptor.java | 3 +- .../hadoop/hbase/client/TestClientNoCluster.java | 10 +- .../org/apache/hadoop/hbase/client/TestScan.java | 40 ++++---- .../apache/hadoop/hbase/TestCellComparator.java | 14 ++- .../java/org/apache/hadoop/hbase/TestKeyValue.java | 16 ++-- .../java/org/apache/hadoop/hbase/TestTimeout.java | 10 +- .../org/apache/hadoop/hbase/util/TestAvlUtil.java | 4 +- .../hadoop/hbase/util/TestByteBufferUtils.java | 8 +- .../hbase/TestCompatibilitySingletonFactory.java | 2 +- .../MetricsStochasticBalancerSourceImpl.java | 2 +- .../MetricsRegionServerSourceFactoryImpl.java | 2 +- .../hadoop/hbase/http/conf/TestConfServlet.java | 6 +- .../hbase/procedure2/TestProcedureNonce.java | 102 ++++++++++----------- .../store/wal/TestWALProcedureStore.java | 11 --- .../apache/hadoop/hbase/io/hfile/CacheConfig.java | 12 +-- .../hbase/master/assignment/AssignmentManager.java | 2 +- .../hadoop/hbase/regionserver/ScannerContext.java | 2 +- .../regionserver/ReplicationSourceManager.java | 6 +- .../hbase/security/access/AccessController.java | 4 +- .../replication/TestReplicationTrackerZKImpl.java | 4 +- .../apache/hadoop/hbase/HBaseZKTestingUtility.java | 25 ++--- .../hbase/zookeeper/TestRecoverableZooKeeper.java | 2 +- .../hadoop/hbase/zookeeper/TestZKMainServer.java | 4 +- 24 files changed, 132 insertions(+), 164 deletions(-) diff --git a/hbase-build-configuration/pom.xml b/hbase-build-configuration/pom.xml index a617083e48..67b646fdd4 100644 --- a/hbase-build-configuration/pom.xml +++ b/hbase-build-configuration/pom.xml @@ -81,7 +81,10 @@ true -XepDisableWarningsInGeneratedCode - -Xep:FallThrough:OFF + + -Xep:FallThrough:OFF + -Xep:WaitNotInLoop:OFF + -Xep:ClassNewInstance:ERROR -Xep:MissingDefault:ERROR diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/PreemptiveFastFailInterceptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/PreemptiveFastFailInterceptor.java index 7b6bba3d83..77509b7df4 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/PreemptiveFastFailInterceptor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/PreemptiveFastFailInterceptor.java @@ -89,7 +89,8 @@ class PreemptiveFastFailInterceptor extends RetryingCallerInterceptor { // fast fail mode for any reason. private long fastFailClearingTimeMilliSec; - private final ThreadLocal threadRetryingInFastFailMode = new ThreadLocal<>(); + private static final ThreadLocal threadRetryingInFastFailMode = + new ThreadLocal<>(); public PreemptiveFastFailInterceptor(Configuration conf) { this.fastFailThresholdMilliSec = conf.getLong( diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java index 3cab09dec5..9d063162b2 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestClientNoCluster.java @@ -17,6 +17,7 @@ */ package org.apache.hadoop.hbase.client; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -172,9 +173,6 @@ public class TestClientNoCluster extends Configured implements Tool { // I expect this exception. LOG.info("Got expected exception", e); t = e; - } catch (RetriesExhaustedException e) { - // This is the old, unwanted behavior. If we get here FAIL!!! - fail(); } finally { table.close(); } @@ -206,18 +204,16 @@ public class TestClientNoCluster extends Configured implements Tool { try { // An exists call turns into a get w/ a flag. table.exists(new Get(Bytes.toBytes("abc"))); + // RetriesExhausedException is old behaviour, if we get it test should fail } catch (SocketTimeoutException e) { // I expect this exception. LOG.info("Got expected exception", e); t = e; - } catch (RetriesExhaustedException e) { - // This is the old, unwanted behavior. If we get here FAIL!!! - fail(); } finally { table.close(); connection.close(); } - assertTrue(t != null); + assertNotNull(t); } @Test diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestScan.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestScan.java index 7ef95245f2..97a6efbf6b 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestScan.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestScan.java @@ -170,22 +170,18 @@ public class TestScan { @Test public void testSetAuthorizations() { Scan scan = new Scan(); - try { - scan.setAuthorizations(new Authorizations("\u002b|\u0029")); - scan.setAuthorizations(new Authorizations("A", "B", "0123", "A0", "1A1", "_a")); - scan.setAuthorizations(new Authorizations("A|B")); - scan.setAuthorizations(new Authorizations("A&B")); - scan.setAuthorizations(new Authorizations("!B")); - scan.setAuthorizations(new Authorizations("A", "(A)")); - scan.setAuthorizations(new Authorizations("A", "{A")); - scan.setAuthorizations(new Authorizations(" ")); - scan.setAuthorizations(new Authorizations(":B")); - scan.setAuthorizations(new Authorizations("-B")); - scan.setAuthorizations(new Authorizations(".B")); - scan.setAuthorizations(new Authorizations("/B")); - } catch (IllegalArgumentException e) { - fail("should not throw exception"); - } + scan.setAuthorizations(new Authorizations("\u002b|\u0029")); + scan.setAuthorizations(new Authorizations("A", "B", "0123", "A0", "1A1", "_a")); + scan.setAuthorizations(new Authorizations("A|B")); + scan.setAuthorizations(new Authorizations("A&B")); + scan.setAuthorizations(new Authorizations("!B")); + scan.setAuthorizations(new Authorizations("A", "(A)")); + scan.setAuthorizations(new Authorizations("A", "{A")); + scan.setAuthorizations(new Authorizations(" ")); + scan.setAuthorizations(new Authorizations(":B")); + scan.setAuthorizations(new Authorizations("-B")); + scan.setAuthorizations(new Authorizations(".B")); + scan.setAuthorizations(new Authorizations("/B")); } @Test @@ -194,24 +190,24 @@ public class TestScan { scan.setStartRow(null); scan.setStartRow(new byte[1]); scan.setStartRow(new byte[HConstants.MAX_ROW_LENGTH]); + boolean threwException = false; try { scan.setStartRow(new byte[HConstants.MAX_ROW_LENGTH+1]); - fail("should've thrown exception"); } catch (IllegalArgumentException iae) { - } catch (Exception e) { - fail("expected IllegalArgumentException to be thrown"); + threwException = true; } + assertTrue("Should have thrown IllegalArgumentException", threwException); scan.setStopRow(null); scan.setStopRow(new byte[1]); scan.setStopRow(new byte[HConstants.MAX_ROW_LENGTH]); + threwException = false; try { scan.setStopRow(new byte[HConstants.MAX_ROW_LENGTH+1]); - fail("should've thrown exception"); } catch (IllegalArgumentException iae) { - } catch (Exception e) { - fail("expected IllegalArgumentException to be thrown"); + threwException = true; } + assertTrue("Should have thrown IllegalArgumentException", threwException); } @Test diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java index a318515832..539f5b4316 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java @@ -228,17 +228,15 @@ public class TestCellComparator { // Add to set with bad comparator Collections.addAll(set, keys); // This will output the keys incorrectly. - boolean assertion = false; + boolean foundIncorrect = false; int count = 0; - try { - for (Cell k: set) { - assertTrue("count=" + count + ", " + k.toString(), count++ == k.getTimestamp()); + for (Cell c : set) { + if(count++ != c.getTimestamp()) { + foundIncorrect = true; + break; } - } catch (AssertionError e) { - // Expected - assertion = true; } - assertTrue(assertion); + assertTrue(foundIncorrect); // Make set with good comparator set = new TreeSet<>(CellComparatorImpl.META_COMPARATOR); Collections.addAll(set, keys); diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java index 167a0302f4..0807fe2e9e 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java @@ -254,22 +254,20 @@ public class TestKeyValue { // Add to set with bad comparator Collections.addAll(set, keys); // This will output the keys incorrectly. - boolean assertion = false; + boolean foundIncorrect = false; int count = 0; - try { - for (KeyValue k: set) { - assertTrue(count++ == k.getTimestamp()); + for (KeyValue k : set) { + if(count++ != k.getTimestamp()) { + foundIncorrect = true; + break; } - } catch (java.lang.AssertionError e) { - // Expected - assertion = true; } - assertTrue(assertion); + assertTrue(foundIncorrect); // Make set with good comparator set = new TreeSet<>(CellComparatorImpl.META_COMPARATOR); Collections.addAll(set, keys); count = 0; - for (KeyValue k: set) { + for (KeyValue k : set) { assertTrue(count++ == k.getTimestamp()); } } diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java index d547ddb420..b7543be65a 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java @@ -43,13 +43,11 @@ public class TestTimeout { @Ignore @Test public void infiniteLoop() { // Launch a background non-daemon thread. - Thread t = new Thread("HangingThread") { - public void run() { - synchronized(this) { - while(true) {} - } + Thread t = new Thread(() -> { + synchronized(this) { + while(true) {} } - }; + }, "HangingThread"); t.start(); while (true) {} } diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestAvlUtil.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestAvlUtil.java index 53544ef944..07cc684e80 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestAvlUtil.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestAvlUtil.java @@ -20,10 +20,12 @@ package org.apache.hadoop.hbase.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.util.Random; import java.util.TreeMap; + import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.testclassification.MiscTests; import org.apache.hadoop.hbase.testclassification.SmallTests; @@ -75,7 +77,7 @@ public class TestAvlUtil { int key = rand.nextInt(MAX_KEY); TestAvlNode node = AvlTree.get(root, key, KEY_COMPARATOR); if (!treeMap.containsKey(key)) { - assert node == null; + assertNull(node); continue; } treeMap.remove(key); diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java index 997a0bb4b5..198f16d90b 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteBufferUtils.java @@ -202,7 +202,7 @@ public class TestByteBufferUtils { * Test copying to stream from buffer. */ @Test - public void testMoveBufferToStream() { + public void testMoveBufferToStream() throws IOException { final int arrayOffset = 7; final int initialPosition = 10; final int endPadding = 5; @@ -216,11 +216,7 @@ public class TestByteBufferUtils { assertEquals(0, buffer.position()); buffer.position(initialPosition); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - try { - ByteBufferUtils.moveBufferToStream(bos, buffer, array.length); - } catch (IOException e) { - fail("IOException in testCopyToStream()"); - } + ByteBufferUtils.moveBufferToStream(bos, buffer, array.length); assertArrayEquals(array, bos.toByteArray()); assertEquals(initialPosition + array.length, buffer.position()); } diff --git a/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/TestCompatibilitySingletonFactory.java b/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/TestCompatibilitySingletonFactory.java index a57c935651..60bdd00c02 100644 --- a/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/TestCompatibilitySingletonFactory.java +++ b/hbase-hadoop-compat/src/test/java/org/apache/hadoop/hbase/TestCompatibilitySingletonFactory.java @@ -43,7 +43,7 @@ public class TestCompatibilitySingletonFactory { private static final int ITERATIONS = 100000; private static final Random RANDOM = new Random(); - private class TestCompatibilitySingletonFactoryCallable implements Callable { + private static class TestCompatibilitySingletonFactoryCallable implements Callable { @Override public String call() throws Exception { diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/balancer/MetricsStochasticBalancerSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/balancer/MetricsStochasticBalancerSourceImpl.java index 3b4ba363b1..b51bc968e1 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/balancer/MetricsStochasticBalancerSourceImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/master/balancer/MetricsStochasticBalancerSourceImpl.java @@ -37,7 +37,7 @@ public class MetricsStochasticBalancerSourceImpl extends MetricsBalancerSourceIm private int metricsSize = 1000; private int mruCap = calcMruCap(metricsSize); - private Map> stochasticCosts = + private final Map> stochasticCosts = new LinkedHashMap>(mruCap, MRU_LOAD_FACTOR, true) { private static final long serialVersionUID = 8204713453436906599L; diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java index 2e6b458691..af80e1a98f 100644 --- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java +++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceFactoryImpl.java @@ -29,7 +29,7 @@ import org.apache.yetus.audience.InterfaceAudience; public class MetricsRegionServerSourceFactoryImpl implements MetricsRegionServerSourceFactory { public static enum FactoryStorage { INSTANCE; - private Object aggLock = new Object(); + private final Object aggLock = new Object(); private MetricsRegionAggregateSourceImpl aggImpl; private MetricsTableAggregateSourceImpl tblAggImpl; private MetricsHeapMemoryManagerSourceImpl heapMemMngImpl; diff --git a/hbase-http/src/test/java/org/apache/hadoop/hbase/http/conf/TestConfServlet.java b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/conf/TestConfServlet.java index 53e129fa87..3f8886710c 100644 --- a/hbase-http/src/test/java/org/apache/hadoop/hbase/http/conf/TestConfServlet.java +++ b/hbase-http/src/test/java/org/apache/hadoop/hbase/http/conf/TestConfServlet.java @@ -39,12 +39,16 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + /** * Basic test case that the ConfServlet can write configuration * to its output in XML and JSON format. */ @Category({MiscTests.class, SmallTests.class}) -public class TestConfServlet extends TestCase { +public class TestConfServlet { @ClassRule public static final HBaseClassTestRule CLASS_RULE = diff --git a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureNonce.java b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureNonce.java index b702314dc7..23991b3c11 100644 --- a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureNonce.java +++ b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/TestProcedureNonce.java @@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.procedure2; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -173,6 +174,7 @@ public class TestProcedureNonce { testConcurrentNonceRegistration(false, 890, 55555); } + @SuppressWarnings("AssertionFailureIgnored") // We keep the exception and verify it later private void testConcurrentNonceRegistration(final boolean submitProcedure, final long nonceGroup, final long nonce) throws IOException { // register the nonce @@ -184,66 +186,60 @@ public class TestProcedureNonce { final CountDownLatch t1NonceRegisteredLatch = new CountDownLatch(1); final CountDownLatch t2BeforeNonceRegisteredLatch = new CountDownLatch(1); final Thread[] threads = new Thread[2]; - threads[0] = new Thread() { - @Override - public void run() { - try { - // release the nonce and wake t2 - assertFalse("unexpected already registered nonce", - procExecutor.registerNonce(nonceKey) >= 0); - t1NonceRegisteredLatch.countDown(); - - // hold the submission until t2 is registering the nonce - t2BeforeNonceRegisteredLatch.await(); - Threads.sleep(1000); - - if (submitProcedure) { - CountDownLatch latch = new CountDownLatch(1); - TestSingleStepProcedure proc = new TestSingleStepProcedure(); - procEnv.setWaitLatch(latch); - - procExecutor.submitProcedure(proc, nonceKey); - Threads.sleep(100); - - // complete the procedure - latch.countDown(); - } else { - procExecutor.unregisterNonceIfProcedureWasNotSubmitted(nonceKey); - } - } catch (Throwable e) { - t1Exception.set(e); - } finally { - t1NonceRegisteredLatch.countDown(); - t2BeforeNonceRegisteredLatch.countDown(); + threads[0] = new Thread(() -> { + try { + // release the nonce and wake t2 + assertFalse("unexpected already registered nonce", + procExecutor.registerNonce(nonceKey) >= 0); + t1NonceRegisteredLatch.countDown(); + + // hold the submission until t2 is registering the nonce + t2BeforeNonceRegisteredLatch.await(); + Threads.sleep(1000); + + if (submitProcedure) { + CountDownLatch latch = new CountDownLatch(1); + TestSingleStepProcedure proc = new TestSingleStepProcedure(); + procEnv.setWaitLatch(latch); + + procExecutor.submitProcedure(proc, nonceKey); + Threads.sleep(100); + + // complete the procedure + latch.countDown(); + } else { + procExecutor.unregisterNonceIfProcedureWasNotSubmitted(nonceKey); } + } catch (Throwable e) { + t1Exception.set(e); + } finally { + t1NonceRegisteredLatch.countDown(); + t2BeforeNonceRegisteredLatch.countDown(); } - }; - - threads[1] = new Thread() { - @Override - public void run() { - try { - // wait until t1 has registered the nonce - t1NonceRegisteredLatch.await(); - - // register the nonce - t2BeforeNonceRegisteredLatch.countDown(); - assertFalse("unexpected non registered nonce", - procExecutor.registerNonce(nonceKey) < 0); - } catch (Throwable e) { - t2Exception.set(e); - } finally { - t1NonceRegisteredLatch.countDown(); - t2BeforeNonceRegisteredLatch.countDown(); - } + }); + + threads[1] = new Thread(() -> { + try { + // wait until t1 has registered the nonce + t1NonceRegisteredLatch.await(); + + // register the nonce + t2BeforeNonceRegisteredLatch.countDown(); + assertFalse("unexpected non registered nonce", + procExecutor.registerNonce(nonceKey) < 0); + } catch (Throwable e) { + t2Exception.set(e); + } finally { + t1NonceRegisteredLatch.countDown(); + t2BeforeNonceRegisteredLatch.countDown(); } - }; + }); for (int i = 0; i < threads.length; ++i) threads[i].start(); for (int i = 0; i < threads.length; ++i) Threads.shutdown(threads[i]); ProcedureTestingUtility.waitNoProcedureRunning(procExecutor); - assertEquals(null, t1Exception.get()); - assertEquals(null, t2Exception.get()); + assertNull(t1Exception.get()); + assertNull(t2Exception.get()); } public static class TestSingleStepProcedure extends SequentialProcedure { diff --git a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/store/wal/TestWALProcedureStore.java b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/store/wal/TestWALProcedureStore.java index 64cf211161..4e34dc6b27 100644 --- a/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/store/wal/TestWALProcedureStore.java +++ b/hbase-procedure/src/test/java/org/apache/hadoop/hbase/procedure2/store/wal/TestWALProcedureStore.java @@ -926,17 +926,6 @@ public class TestWALProcedureStore { assertEquals(0, loader.getCorruptedCount()); } - private void assertEmptyLogDir() { - try { - FileStatus[] status = fs.listStatus(logDir); - assertTrue("expected empty state-log dir", status == null || status.length == 0); - } catch (FileNotFoundException e) { - fail("expected the state-log dir to be present: " + logDir); - } catch (IOException e) { - fail("got en exception on state-log dir list: " + e.getMessage()); - } - } - public static class TestSequentialProcedure extends SequentialProcedure { private static long seqid = 0; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java index ac1af91617..c920209b64 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java @@ -150,18 +150,16 @@ public class CacheConfig { * Enum of all built in external block caches. * This is used for config. */ - private static enum ExternalBlockCaches { + private enum ExternalBlockCaches { memcached("org.apache.hadoop.hbase.io.hfile.MemcachedBlockCache"); // TODO(eclark): Consider more. Redis, etc. - Class clazz; + final Class clazz; ExternalBlockCaches(String clazzName) { + Class clazz = null; try { - clazz = (Class) Class.forName(clazzName); - } catch (ClassNotFoundException cnef) { - clazz = null; + clazz = Class.forName(clazzName).asSubclass(BlockCache.class); + } catch (ClassNotFoundException ignored) { } - } - ExternalBlockCaches(Class clazz) { this.clazz = clazz; } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java index 3412c82f2d..7ddc274793 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/AssignmentManager.java @@ -1715,7 +1715,7 @@ public class AssignmentManager implements ServerListener { if (!isRunning()) return null; assignQueueFullCond.await(assignDispatchWaitMillis, TimeUnit.MILLISECONDS); - regions = new HashMap(pendingAssignQueue.size()); + regions = new HashMap<>(pendingAssignQueue.size() * 2); for (RegionStateNode regionNode: pendingAssignQueue) { regions.put(regionNode.getRegionInfo(), regionNode); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScannerContext.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScannerContext.java index cc6ec84f0a..4afad9726d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScannerContext.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/ScannerContext.java @@ -438,7 +438,7 @@ public class ScannerContext { private final boolean moreValues; private final boolean limitReached; - private NextState(boolean moreValues, boolean limitReached) { + NextState(boolean moreValues, boolean limitReached) { this.moreValues = moreValues; this.limitReached = limitReached; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java index a370867cfe..f2e0bc568c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java @@ -392,11 +392,13 @@ public class ReplicationSourceManager implements ReplicationListener { // synchronized on oldsources to avoid race with NodeFailoverWorker synchronized (this.oldsources) { List previousQueueIds = new ArrayList<>(); - for (ReplicationSourceInterface oldSource : this.oldsources) { + Iterator iterator = this.oldsources.iterator(); + while (iterator.hasNext()) { + ReplicationSourceInterface oldSource = iterator.next(); if (oldSource.getPeerId().equals(peerId)) { previousQueueIds.add(oldSource.getQueueId()); oldSource.terminate(terminateMessage); - this.oldsources.remove(oldSource); + iterator.remove(); } } for (String queueId : previousQueueIds) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java index 2758c7e379..8b2d1b2edd 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java @@ -515,9 +515,9 @@ public class AccessController implements MasterCoprocessor, RegionCoprocessor, APPEND("append"), INCREMENT("increment"); - private String type; + private final String type; - private OpType(String type) { + OpType(String type) { this.type = type; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java index 65eac4a9f0..998ab0990c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java @@ -82,13 +82,13 @@ public class TestReplicationTrackerZKImpl { utility = new HBaseTestingUtility(); utility.startMiniZKCluster(); conf = utility.getConfiguration(); - ZKWatcher zk = HBaseTestingUtility.getZooKeeperWatcher(utility); + ZkWatcher zk = utility.getZooKeeperWatcher(); ZKUtil.createWithParents(zk, zk.getZNodePaths().rsZNode); } @Before public void setUp() throws Exception { - zkw = HBaseTestingUtility.getZooKeeperWatcher(utility); + zkw = utility.getZooKeeperWatcher(); String fakeRs1 = ZNodePaths.joinZNode(zkw.getZNodePaths().rsZNode, "hostname1.example.org:1234"); try { diff --git a/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/HBaseZKTestingUtility.java b/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/HBaseZKTestingUtility.java index b755c32c44..a3d4e213f7 100644 --- a/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/HBaseZKTestingUtility.java +++ b/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/HBaseZKTestingUtility.java @@ -164,15 +164,18 @@ public class HBaseZKTestingUtility extends HBaseCommonTestingUtility { */ public synchronized ZKWatcher getZooKeeperWatcher() throws IOException { if (zooKeeperWatcher == null) { + boolean aborted = false; + zooKeeperWatcher = new ZKWatcher(conf, "testing utility", new Abortable() { @Override public void abort(String why, Throwable e) { + aborted = true; throw new RuntimeException("Unexpected abort in HBaseZKTestingUtility:" + why, e); } @Override public boolean isAborted() { - return false; + return aborted; } }); } @@ -181,23 +184,11 @@ public class HBaseZKTestingUtility extends HBaseCommonTestingUtility { /** * Gets a ZKWatcher. + * @deprecated use {@link #getZooKeeperWatcher()} instead */ + @Deprecated public static ZKWatcher getZooKeeperWatcher(HBaseZKTestingUtility testUtil) throws IOException { - ZKWatcher zkw = new ZKWatcher(testUtil.getConfiguration(), "unittest", new Abortable() { - boolean aborted = false; - - @Override - public void abort(String why, Throwable e) { - aborted = true; - throw new RuntimeException("Fatal ZK error, why=" + why, e); - } - - @Override - public boolean isAborted() { - return aborted; - } - }); - return zkw; + return testUtil.getZooKeeperWatcher(); } /** @@ -208,7 +199,7 @@ public class HBaseZKTestingUtility extends HBaseCommonTestingUtility { boolean ret = super.cleanupTestDir(); if (deleteDir(this.clusterTestDir)) { this.clusterTestDir = null; - return ret & true; + return ret; } return false; } diff --git a/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/zookeeper/TestRecoverableZooKeeper.java b/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/zookeeper/TestRecoverableZooKeeper.java index 1e7db05846..4a96939ed3 100644 --- a/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/zookeeper/TestRecoverableZooKeeper.java +++ b/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/zookeeper/TestRecoverableZooKeeper.java @@ -94,7 +94,7 @@ public class TestRecoverableZooKeeper { assertTrue(Bytes.equals(opened, data)); } - class ZookeeperStub extends ZooKeeper { + static class ZookeeperStub extends ZooKeeper { private int throwExceptionInNumOperations; diff --git a/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKMainServer.java b/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKMainServer.java index d1c18d3548..d1aa2ba953 100644 --- a/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKMainServer.java +++ b/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKMainServer.java @@ -115,11 +115,11 @@ public class TestZKMainServer { // multiple servers with its own port c.set("hbase.zookeeper.quorum", "example1.com:5678,example2.com:9012,example3.com:3456"); ensemble = parser.parse(c); - assertEquals(ensemble, "example1.com:5678,example2.com:9012,example3.com:3456"); + assertEquals("example1.com:5678,example2.com:9012,example3.com:3456", ensemble); // some servers without its own port, which will be assigned the default client port c.set("hbase.zookeeper.quorum", "example1.com:5678,example2.com:9012,example3.com"); ensemble = parser.parse(c); - assertEquals(ensemble, "example1.com:5678,example2.com:9012,example3.com:" + port); + assertEquals("example1.com:5678,example2.com:9012,example3.com:" + port, ensemble); } } -- 2.16.1