Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit d04da699 authored by Cole Faust's avatar Cole Faust Committed by Michael Bestas
Browse files

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
parent ddb44600
Loading
Loading
Loading
Loading
+15 −13
Original line number Diff line number Diff line
@@ -24,9 +24,11 @@ import android.provider.MediaStore.MediaColumns;
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,34 +221,34 @@ public class ApiHelper {
    }

    private static boolean hasField(Class<?> klass, String fieldName) {
        try {
            klass.getDeclaredField(fieldName);
        for (Field f : klass.getDeclaredFields()) {
            if (f.getName().equals(fieldName)) {
                return true;
        } catch (NoSuchFieldException e) {
            return false;
            }
        }
        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);
        for (Method method : klass.getDeclaredMethods()) {
            if (method.getName().equals(methodName) &&
                Arrays.equals(method.getParameterTypes(), paramTypes)) {
                return true;
        } catch (NoSuchMethodException e) {
            return false;
            }
        }
        return false;
    }

    private static Class<?> getClassForName(String className) {
        Class<?> klass = null;
+1 −0
Original line number Diff line number Diff line
@@ -2561,6 +2561,7 @@ public class FilterShowActivity extends AbstractPermissionActivity implements On
                requestCode);
    }

    @SuppressWarnings("MissingSuperCall") // TODO: Fix me
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
+2 −3
Original line number Diff line number Diff line
@@ -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 @@ public class ControlPoint implements Comparable {
    }

    @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) {