Enable error prone against CTS harness

- start enabling error prone against the CTS harness to
ensure some basic checking.

Test: make cts javac-check -j64 TARGET_PRODUCT=aosp_arm64
WITH_DEXPREOPT=false RUN_ERROR_PRONE=true
Bug: 37854485

Change-Id: I1ecc61d89d67d4d3a22bcd2f10c5152a62ad6cb4
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/SubPlanHelper.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/SubPlanHelper.java
index 950a129..21cb203 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/SubPlanHelper.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/SubPlanHelper.java
@@ -307,7 +307,7 @@
         Set<TestStatus> statusesToRun = new HashSet<TestStatus>();
         for (String resultType : mResultTypes) {
             // no test status exists for not-executed tests
-            if (resultType != NOT_EXECUTED) {
+            if (!NOT_EXECUTED.equals(resultType)) {
                 statusesToRun.add(STATUS_MAP.get(resultType));
             }
         }
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/DeviceInfoCollector.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/DeviceInfoCollector.java
index 6237c23..d48e9f6 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/DeviceInfoCollector.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/DeviceInfoCollector.java
@@ -31,8 +31,6 @@
 
 import java.io.File;
 import java.io.FileNotFoundException;
-import java.util.HashMap;
-import java.util.Map;
 import java.util.Map.Entry;
 
 /**
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/PreconditionPreparer.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/PreconditionPreparer.java
index 27ef658..d47b56c 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/PreconditionPreparer.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/targetprep/PreconditionPreparer.java
@@ -49,7 +49,7 @@
                     + "\"<arg-name>:<arg-value>\"")
     private List<String> mPreconditionArgs = new ArrayList<>();
 
-    protected final String LOG_TAG = getClass().getSimpleName();
+    protected final String mLogTag = getClass().getSimpleName();
 
     @Override
     public void setUp(ITestDevice device, IBuildInfo buildInfo) throws TargetSetupError,
@@ -80,32 +80,32 @@
             throws TargetSetupError, BuildError, DeviceNotAvailableException;
 
     protected void logInfo(String info) {
-        LogUtil.printLog(Log.LogLevel.INFO, LOG_TAG, info);
+        LogUtil.printLog(Log.LogLevel.INFO, mLogTag, info);
     }
 
     protected void logInfo(String infoFormat, Object... args) {
-        LogUtil.printLog(Log.LogLevel.INFO, LOG_TAG, String.format(infoFormat, args));
+        LogUtil.printLog(Log.LogLevel.INFO, mLogTag, String.format(infoFormat, args));
     }
 
     protected void logWarning(String warning) {
-        LogUtil.printLog(Log.LogLevel.WARN, LOG_TAG, warning);
+        LogUtil.printLog(Log.LogLevel.WARN, mLogTag, warning);
     }
 
     protected void logWarning(String warningFormat, Object... args) {
-        LogUtil.printLog(Log.LogLevel.WARN, LOG_TAG, String.format(warningFormat, args));
+        LogUtil.printLog(Log.LogLevel.WARN, mLogTag, String.format(warningFormat, args));
     }
 
     protected void logError(String error) {
-        LogUtil.printLog(Log.LogLevel.ERROR, LOG_TAG, error);
+        LogUtil.printLog(Log.LogLevel.ERROR, mLogTag, error);
     }
 
     protected void logError(String errorFormat, Object... args) {
-        LogUtil.printLog(Log.LogLevel.ERROR, LOG_TAG, String.format(errorFormat, args));
+        LogUtil.printLog(Log.LogLevel.ERROR, mLogTag, String.format(errorFormat, args));
     }
 
     protected void logError(Throwable t) {
         if (t != null) {
-            Log.e(LOG_TAG, t);
+            Log.e(mLogTag, t);
         }
     }
 
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/util/RetryFilterHelper.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/util/RetryFilterHelper.java
index 4ff3953..c359a90 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/util/RetryFilterHelper.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/util/RetryFilterHelper.java
@@ -19,8 +19,8 @@
 import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper;
 import com.android.compatibility.common.tradefed.result.SubPlanHelper;
 import com.android.compatibility.common.tradefed.testtype.CompatibilityTest;
-import com.android.compatibility.common.tradefed.testtype.ModuleRepo;
 import com.android.compatibility.common.tradefed.testtype.ISubPlan;
+import com.android.compatibility.common.tradefed.testtype.ModuleRepo;
 import com.android.compatibility.common.util.IInvocationResult;
 import com.android.compatibility.common.util.LightInvocationResult;
 import com.android.compatibility.common.util.ResultHandler;
@@ -33,7 +33,6 @@
 import com.android.tradefed.config.OptionSetter;
 import com.android.tradefed.device.DeviceNotAvailableException;
 import com.android.tradefed.device.ITestDevice;
-import com.android.tradefed.log.LogUtil.CLog;
 import com.android.tradefed.util.ArrayUtil;
 
 import java.io.FileNotFoundException;
diff --git a/common/host-side/tradefed/tests/Android.mk b/common/host-side/tradefed/tests/Android.mk
index 6bc8bc9..0a61c28 100644
--- a/common/host-side/tradefed/tests/Android.mk
+++ b/common/host-side/tradefed/tests/Android.mk
@@ -19,6 +19,7 @@
 
 LOCAL_SRC_FILES := $(call all-java-files-under, ../src)
 LOCAL_JAVA_RESOURCE_DIRS := ../res
+include cts/error_prone_rules.mk
 
 LOCAL_SUITE_BUILD_NUMBER := 2
 LOCAL_SUITE_TARGET_ARCH := $(TARGET_ARCH)
@@ -36,6 +37,7 @@
 LOCAL_SRC_FILES := $(call all-java-files-under, src)
 LOCAL_JAVA_RESOURCE_DIRS := res
 
+include cts/error_prone_rules.mk
 LOCAL_MODULE := compatibility-tradefed-tests
 
 LOCAL_MODULE_TAGS := optional
diff --git a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ValidateTestsAbi.java b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ValidateTestsAbi.java
index b85a036..fea023c 100644
--- a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ValidateTestsAbi.java
+++ b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/presubmit/ValidateTestsAbi.java
@@ -48,9 +48,9 @@
      *  This particular module is shipping all it's dependencies in all abis with prebuilt stuff.
      *  Excluding it for now to have the test setup.
      */
-    private String MODULE_EXCEPTION = "CtsSplitApp";
+    private static final String MODULE_EXCEPTION = "CtsSplitApp";
 
-    private static Set<String> BINARY_EXCEPTIONS = new HashSet<>();
+    private static final Set<String> BINARY_EXCEPTIONS = new HashSet<>();
     static {
         /**
          * This binary is a host side helper, so we do not need to check it.
diff --git a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/util/CollectorUtilTest.java b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/util/CollectorUtilTest.java
index 5e06d26..3f13671 100644
--- a/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/util/CollectorUtilTest.java
+++ b/common/host-side/tradefed/tests/src/com/android/compatibility/common/tradefed/util/CollectorUtilTest.java
@@ -22,7 +22,7 @@
  */
 public class CollectorUtilTest extends TestCase {
 
-    String UNFORMATTED_JSON = "{"
+    private static final String UNFORMATTED_JSON = "{"
             + "\"stream_name_1\":"
             + "{\"id\":1,\"key1\":\"value1\"},"
             + "\"stream_name_2\":"
@@ -31,7 +31,7 @@
             + "{\"id\":2,\"key1\":\"value2\"},"
             + "}";
 
-    String REFORMATTED_JSON = "{"
+    private static final String REFORMATTED_JSON = "{"
             + "\"stream_name_2\":"
             + "["
             + "{\"id\":1,\"key1\":\"value3\"}"
diff --git a/error_prone_rules.mk b/error_prone_rules.mk
new file mode 100644
index 0000000..96b340e
--- /dev/null
+++ b/error_prone_rules.mk
@@ -0,0 +1,29 @@
+# Copyright (C) 2017 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Set of error prone rules to ensure code quality
+LOCAL_ERROR_PRONE_FLAGS:= -Xep:ArrayToString:ERROR \
+                          -Xep:BoxedPrimitiveConstructor:ERROR \
+                          -Xep:ConstantField:ERROR \
+                          -Xep:FormatString:ERROR \
+                          -Xep:JUnitAmbiguousTestClass:ERROR \
+                          -Xep:MissingFail:ERROR \
+                          -Xep:MissingOverride:ERROR \
+                          -Xep:Overrides:ERROR \
+                          -Xep:ReferenceEquality:ERROR \
+                          -Xep:RemoveUnusedImports:ERROR \
+                          -Xep:ReturnValueIgnored:ERROR \
+                          -Xep:SelfEquals:ERROR \
+                          -Xep:SizeGreaterThanOrEqualsZero:ERROR
+
diff --git a/tools/cts-tradefed/Android.mk b/tools/cts-tradefed/Android.mk
index 7783e58..a247d06 100644
--- a/tools/cts-tradefed/Android.mk
+++ b/tools/cts-tradefed/Android.mk
@@ -28,7 +28,7 @@
 LOCAL_SUITE_VERSION := 7.1_r2
 
 LOCAL_MODULE := cts-tradefed
-
+include cts/error_prone_rules.mk
 include $(BUILD_COMPATIBILITY_SUITE)
 
 # Build all sub-directories