From 91909de09c8b06a2fb3a38e7c8c9eb7f09a7194f Mon Sep 17 00:00:00 2001 From: Andrew Purtell Date: Mon, 8 Sep 2014 17:17:02 -0700 Subject: [PATCH] HBASE-11912 Catch some bad practices at compile time with error-prone --- .../org/apache/hadoop/hbase/ClusterStatus.java | 11 +++--- .../org/apache/hadoop/hbase/zookeeper/ZKUtil.java | 2 + .../apache/hadoop/hbase/client/HTableWrapper.java | 4 +- .../hadoop/hbase/coprocessor/RegionObserver.java | 4 ++ .../hadoop/hbase/util/hbck/OfflineMetaRepair.java | 2 +- .../apache/hadoop/hbase/thrift2/HTablePool.java | 3 ++ pom.xml | 46 +++++++++++++++++++++- 7 files changed, 64 insertions(+), 8 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java index 236304c..2bd2325 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ClusterStatus.java @@ -216,6 +216,7 @@ public class ClusterStatus extends VersionedWritable { * @return region server information * @deprecated Use {@link #getServers()} */ + @Deprecated public Collection getServerInfo() { return getServers(); } @@ -378,7 +379,7 @@ public class ClusterStatus extends VersionedWritable { public static ClusterStatus convert(ClusterStatusProtos.ClusterStatus proto) { Map servers = null; - if (proto.getLiveServersList() != null) { + if (!proto.getLiveServersList().isEmpty()) { servers = new HashMap(proto.getLiveServersList().size()); for (LiveServerInfo lsi : proto.getLiveServersList()) { servers.put(ProtobufUtil.toServerName( @@ -387,7 +388,7 @@ public class ClusterStatus extends VersionedWritable { } Collection deadServers = null; - if (proto.getDeadServersList() != null) { + if (!proto.getDeadServersList().isEmpty()) { deadServers = new ArrayList(proto.getDeadServersList().size()); for (HBaseProtos.ServerName sn : proto.getDeadServersList()) { deadServers.add(ProtobufUtil.toServerName(sn)); @@ -395,7 +396,7 @@ public class ClusterStatus extends VersionedWritable { } Collection backupMasters = null; - if (proto.getBackupMastersList() != null) { + if (!proto.getBackupMastersList().isEmpty()) { backupMasters = new ArrayList(proto.getBackupMastersList().size()); for (HBaseProtos.ServerName sn : proto.getBackupMastersList()) { backupMasters.add(ProtobufUtil.toServerName(sn)); @@ -403,7 +404,7 @@ public class ClusterStatus extends VersionedWritable { } Map rit = null; - if (proto.getRegionsInTransitionList() != null) { + if (!proto.getRegionsInTransitionList().isEmpty()) { rit = new HashMap(proto.getRegionsInTransitionList().size()); for (RegionInTransition region : proto.getRegionsInTransitionList()) { String key = new String(region.getSpec().getValue().toByteArray()); @@ -413,7 +414,7 @@ public class ClusterStatus extends VersionedWritable { } String[] masterCoprocessors = null; - if (proto.getMasterCoprocessorsList() != null) { + if (!proto.getMasterCoprocessorsList().isEmpty()) { final int numMasterCoprocessors = proto.getMasterCoprocessorsCount(); masterCoprocessors = new String[numMasterCoprocessors]; for (int i = 0; i < numMasterCoprocessors; i++) { diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java index 79fa4ba..85f3eed 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java @@ -801,6 +801,7 @@ public class ZKUtil { * @throws KeeperException if unexpected zookeeper exception * @deprecated Unused */ + @Deprecated public static List getChildDataAndWatchForNewChildren( ZooKeeperWatcher zkw, String baseNode) throws KeeperException { List nodes = @@ -833,6 +834,7 @@ public class ZKUtil { * @throws KeeperException.BadVersionException if version mismatch * @deprecated Unused */ + @Deprecated public static void updateExistingNodeData(ZooKeeperWatcher zkw, String znode, byte [] data, int expectedVersion) throws KeeperException { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTableWrapper.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTableWrapper.java index fa28eac..372af5e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTableWrapper.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HTableWrapper.java @@ -253,6 +253,7 @@ public class HTableWrapper implements HTableInterface { * @deprecated If any exception is thrown by one of the actions, there is no way to * retrieve the partially executed results. Use {@link #batch(List, Object[])} instead. */ + @Deprecated @Override public Object[] batch(List actions) throws IOException, InterruptedException { @@ -272,6 +273,7 @@ public class HTableWrapper implements HTableInterface { * {@link #batchCallback(List, Object[], org.apache.hadoop.hbase.client.coprocessor.Batch.Callback)} * instead. */ + @Deprecated @Override public Object[] batchCallback(List actions, Batch.Callback callback) throws IOException, InterruptedException { @@ -353,4 +355,4 @@ public class HTableWrapper implements HTableInterface { table.batchCoprocessorService(methodDescriptor, request, startKey, endKey, responsePrototype, callback); } -} \ No newline at end of file +} diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java index 3425a12..e9b39f0 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java @@ -118,6 +118,7 @@ public interface RegionObserver extends Coprocessor { * @throws IOException if an error occurred on the coprocessor * @deprecated use {@link #preFlush(ObserverContext, Store, InternalScanner)} instead */ + @Deprecated void preFlush(final ObserverContext c) throws IOException; /** @@ -138,6 +139,7 @@ public interface RegionObserver extends Coprocessor { * @throws IOException if an error occurred on the coprocessor * @deprecated use {@link #preFlush(ObserverContext, Store, InternalScanner)} instead. */ + @Deprecated void postFlush(final ObserverContext c) throws IOException; /** @@ -339,6 +341,7 @@ public interface RegionObserver extends Coprocessor { * @deprecated Use preSplit( * final ObserverContext c, byte[] splitRow) */ + @Deprecated void preSplit(final ObserverContext c) throws IOException; /** @@ -359,6 +362,7 @@ public interface RegionObserver extends Coprocessor { * @throws IOException if an error occurred on the coprocessor * @deprecated Use postCompleteSplit() instead */ + @Deprecated void postSplit(final ObserverContext c, final HRegion l, final HRegion r) throws IOException; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRepair.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRepair.java index ff93d6a..928bb99 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRepair.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/util/hbck/OfflineMetaRepair.java @@ -80,7 +80,7 @@ public class OfflineMetaRepair { for (int i = 0; i < args.length; i++) { String cmd = args[i]; if (cmd.equals("-details")) { - fsck.setDisplayFullReport(); + HBaseFsck.setDisplayFullReport(); } else if (cmd.equals("-base")) { if (i == args.length - 1) { System.err.println("OfflineMetaRepair: -base needs an HDFS path."); diff --git a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/HTablePool.java b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/HTablePool.java index 0ed6668..8f82f1e 100644 --- a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/HTablePool.java +++ b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift2/HTablePool.java @@ -236,6 +236,7 @@ public class HTablePool implements Closeable { * the proxy table user got from pool * @deprecated */ + @Deprecated public void putTable(HTableInterface table) throws IOException { // we need to be sure nobody puts a proxy implementation in the pool // but if the client code is not updated @@ -396,6 +397,7 @@ public class HTablePool implements Closeable { * @deprecated If any exception is thrown by one of the actions, there is no way to * retrieve the partially executed results. Use {@link #batch(List, Object[])} instead. */ + @Deprecated @Override public Object[] batch(List actions) throws IOException, InterruptedException { @@ -589,6 +591,7 @@ public class HTablePool implements Closeable { * {@link #batchCallback(List, Object[], org.apache.hadoop.hbase.client.coprocessor.Batch.Callback)} * instead. */ + @Deprecated @Override public Object[] batchCallback(List actions, Callback callback) throws IOException, InterruptedException { diff --git a/pom.xml b/pom.xml index 527cda2..73d601f 100644 --- a/pom.xml +++ b/pom.xml @@ -465,7 +465,7 @@ maven-compiler-plugin - 2.5.1 + 3.1 ${compileSource} ${compileSource} @@ -473,6 +473,50 @@ false -Xlint:-options + + + compile-without-errorprone + + compile + + compile + + javac + + **/protobuf/generated/*.java + **/thrift2/generated/*.java + + + + + default-compile + + javac-with-errorprone + true + + **/protobuf/generated/*.java + **/thrift2/generated/*.java + + + + + + + com.google.errorprone + error_prone_core + 1.1.1 + + + org.codehaus.plexus + plexus-compiler-javac + 2.3 + + + org.codehaus.plexus + plexus-compiler-javac-errorprone + 2.3 + + -- 1.8.5.2 (Apple Git-48)