Fix errorprone warnings that should be errors
This commit is part of a large scale change to fix errorprone
errors that have been downgraded to warnings in the android
source tree, so that they can be promoted to errors again.
The full list of changes include the following, but not all
will be present in any one individual commit:
BadAnnotationImplementation
BadShiftAmount
BanJNDI
BoxedPrimitiveEquality
ComparableType
ComplexBooleanConstant
CollectionToArraySafeParameter
ConditionalExpressionNumericPromotion
DangerousLiteralNull
DoubleBraceInitialization
DurationFrom
DurationTemporalUnit
EmptyTopLevelDeclaration
EqualsNull
EqualsReference
FormatString
FromTemporalAccessor
GetClassOnAnnotation
GetClassOnClass
HashtableContains
IdentityBinaryExpression
IdentityHashMapBoxing
InstantTemporalUnit
InvalidTimeZoneID
InvalidZoneId
IsInstanceIncompatibleType
JUnitParameterMethodNotFound
LockOnBoxedPrimitive
MathRoundIntLong
MislabeledAndroidString
MisusedDayOfYear
MissingSuperCall
MisusedWeekYear
ModifyingCollectionWithItself
NoCanIgnoreReturnValueOnClasses
NonRuntimeAnnotation
NullableOnContainingClass
NullTernary
OverridesJavaxInjectableMethod
ParcelableCreator
PeriodFrom
PreconditionsInvalidPlaceholder
ProtoBuilderReturnValueIgnored
ProtoFieldNullComparison
RandomModInteger
RectIntersectReturnValueIgnored
ReturnValueIgnored
SelfAssignment
SelfComparison
SelfEquals
SizeGreaterThanOrEqualsZero
StringBuilderInitWithChar
TreeToString
TryFailThrowable
UnnecessaryCheckNotNull
UnusedCollectionModifiedInPlace
XorPower
See https://errorprone.info/bugpatterns for more
information on the checks.
Bug: 253827323
Test: m RUN_ERROR_PRONE=true javac-check
Change-Id: If22f7e827ef4d3e5766d6cc9f6a78353fbfaa60f
diff --git a/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java b/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
index 4b8d961..87ab7ac 100755
--- a/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
+++ b/gallerycommon/src/com/android/gallery3d/common/ApiHelper.java
@@ -24,9 +24,11 @@
import android.view.View;
import android.view.WindowManager;
+import java.lang.ClassNotFoundException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.util.Arrays;
public class ApiHelper {
public static interface VERSION_CODES {
@@ -219,33 +221,33 @@
}
private static boolean hasField(Class<?> klass, String fieldName) {
- try {
- klass.getDeclaredField(fieldName);
- return true;
- } catch (NoSuchFieldException e) {
- return false;
+ for (Field f : klass.getDeclaredFields()) {
+ if (f.getName().equals(fieldName)) {
+ return true;
+ }
}
+ return false;
}
private static boolean hasMethod(String className, String methodName,
Class<?>... parameterTypes) {
try {
Class<?> klass = Class.forName(className);
- klass.getDeclaredMethod(methodName, parameterTypes);
- return true;
- } catch (Throwable th) {
+ return hasMethod(klass, methodName, parameterTypes);
+ } catch (ClassNotFoundException e) {
return false;
}
}
private static boolean hasMethod(
Class<?> klass, String methodName, Class<?> ... paramTypes) {
- try {
- klass.getDeclaredMethod(methodName, paramTypes);
- return true;
- } catch (NoSuchMethodException e) {
- return false;
+ for (Method method : klass.getDeclaredMethods()) {
+ if (method.getName().equals(methodName) &&
+ Arrays.equals(method.getParameterTypes(), paramTypes)) {
+ return true;
+ }
}
+ return false;
}
private static Class<?> getClassForName(String className) {
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index 1559f27..82ef2cf 100755
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -2561,6 +2561,7 @@
requestCode);
}
+ @SuppressWarnings("MissingSuperCall") // TODO: Fix me
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
diff --git a/src/com/android/gallery3d/filtershow/imageshow/ControlPoint.java b/src/com/android/gallery3d/filtershow/imageshow/ControlPoint.java
index aaec728..cc1f1af 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/ControlPoint.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/ControlPoint.java
@@ -16,7 +16,7 @@
package com.android.gallery3d.filtershow.imageshow;
-public class ControlPoint implements Comparable {
+public class ControlPoint implements Comparable<ControlPoint> {
public float x;
public float y;
@@ -52,8 +52,7 @@
}
@Override
- public int compareTo(Object another) {
- ControlPoint p = (ControlPoint) another;
+ public int compareTo(ControlPoint p) {
if (p.x < x) {
return 1;
} else if (p.x > x) {