From f28dd6859860a4482b04de33e03bb856e093cc28 Mon Sep 17 00:00:00 2001 From: maoling Date: Wed, 21 Feb 2018 22:36:40 +0800 Subject: [PATCH] HBASE-19761:Fix Checkstyle errors in hbase-zookeeper --- hbase-zookeeper/pom.xml | 16 ++++++++++++++++ .../apache/hadoop/hbase/zookeeper/MetaTableLocator.java | 8 ++++---- .../org/apache/hadoop/hbase/zookeeper/ZKMainServer.java | 6 +++--- .../org/apache/hadoop/hbase/zookeeper/ZKWatcher.java | 10 ++++++---- .../hadoop/hbase/zookeeper/TestZKLeaderManager.java | 1 - .../apache/hadoop/hbase/zookeeper/TestZKMainServer.java | 2 +- 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/hbase-zookeeper/pom.xml b/hbase-zookeeper/pom.xml index 8fb5b15144..b993d57a2f 100644 --- a/hbase-zookeeper/pom.xml +++ b/hbase-zookeeper/pom.xml @@ -98,6 +98,22 @@ org.codehaus.mojo findbugs-maven-plugin + + org.apache.maven.plugins + maven-checkstyle-plugin + + + checkstyle + validate + + check + + + true + + + + diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java index 76c12d0c84..4c170f7e74 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/MetaTableLocator.java @@ -388,7 +388,7 @@ public class MetaTableLocator { service = connection.getAdmin(sn); } catch (RetriesExhaustedException e) { if (e.getCause() != null && e.getCause() instanceof ConnectException) { - // Catch this; presume it means the cached connection has gone bad. + LOG.debug("Catch this; presume it means the cached connection has gone bad."); } else { throw e; } @@ -407,12 +407,12 @@ public class MetaTableLocator { } catch (IOException ioe) { Throwable cause = ioe.getCause(); if (ioe instanceof ConnectException) { - // Catch. Connect refused. + LOG.debug("Catch. Connect refused."); } else if (cause != null && cause instanceof EOFException) { - // Catch. Other end disconnected us. + LOG.debug("Catch. Other end disconnected us."); } else if (cause != null && cause.getMessage() != null && cause.getMessage().toLowerCase(Locale.ROOT).contains("connection reset")) { - // Catch. Connection reset. + LOG.debug("Catch. Connection reset."); } else { throw ioe; } diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKMainServer.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKMainServer.java index 2488682bcb..277c422b22 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKMainServer.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKMainServer.java @@ -57,9 +57,9 @@ public class ZKMainServer { /** * Run the command-line args passed. Calls System.exit when done. - * @throws KeeperException - * @throws IOException - * @throws InterruptedException + * @throws KeeperException zookeeper exception + * @throws IOException if fail to runCmdLine + * @throws InterruptedException unexpected thread exception */ void runCmdLine() throws KeeperException, IOException, InterruptedException { processCmd(this.cl); diff --git a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKWatcher.java b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKWatcher.java index 3aac946947..8f64ddb87c 100644 --- a/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKWatcher.java +++ b/hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKWatcher.java @@ -76,14 +76,14 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { // Used if abortable is null private boolean aborted = false; - public final ZNodePaths znodePaths; + protected final ZNodePaths znodePaths; // listeners to be notified private final List listeners = new CopyOnWriteArrayList<>(); // Used by ZKUtil:waitForZKConnectionIfAuthenticating to wait for SASL // negotiation to complete - public CountDownLatch saslLatch = new CountDownLatch(1); + private CountDownLatch saslLatch = new CountDownLatch(1); private final Configuration conf; @@ -95,7 +95,7 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { * @param identifier string that is passed to RecoverableZookeeper to be used as * identifier for this instance. Use null for default. * @throws IOException if the connection to ZooKeeper fails - * @throws ZooKeeperConnectionException + * @throws ZooKeeperConnectionException if the client can't connect to zookeeper */ public ZKWatcher(Configuration conf, String identifier, Abortable abortable) throws ZooKeeperConnectionException, IOException { @@ -111,7 +111,7 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { * context. * @param canCreateBaseZNode true if a base ZNode can be created * @throws IOException if the connection to ZooKeeper fails - * @throws ZooKeeperConnectionException + * @throws ZooKeeperConnectionException if the client can't connect to zookeeper */ public ZKWatcher(Configuration conf, String identifier, Abortable abortable, boolean canCreateBaseZNode) @@ -482,6 +482,8 @@ public class ZKWatcher implements Watcher, Abortable, Closeable { } break; } + default: + throw new IllegalStateException("Received event is not valid: " + event.getState()); } } diff --git a/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKLeaderManager.java b/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKLeaderManager.java index 8371f91c31..432779e9eb 100644 --- a/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKLeaderManager.java +++ b/hbase-zookeeper/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKLeaderManager.java @@ -18,7 +18,6 @@ package org.apache.hadoop.hbase.zookeeper; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; 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 f8052603c1..d1c18d3548 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 @@ -43,7 +43,7 @@ public class TestZKMainServer { // http://stackoverflow.com/questions/309396/java-how-to-test-methods-that-call-system-exit protected static class ExitException extends SecurityException { private static final long serialVersionUID = 1L; - public final int status; + private final int status; public ExitException(int status) { super("There is no escape!"); this.status = status; -- 2.14.1.windows.1