From a54b856e8dc228c13515534202c494a30814fedf Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Sat, 15 Oct 2022 21:33:28 -0700 Subject: [PATCH] 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: Ic7e78cc74523ee09c1b4aa9969756f0cfd609e08 --- .../android/commands/monkey/MonkeySourceScript.java | 4 ++-- .../apis/media/projection/MediaProjectionDemo.java | 13 ++++++------- .../android/mmslib/pdu/EncodedStringValue.java | 1 - 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java index b4db51f1c..eaa9d1ce7 100644 --- a/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java +++ b/cmds/monkey/src/com/android/commands/monkey/MonkeySourceScript.java @@ -245,7 +245,7 @@ public class MonkeySourceScript implements MonkeyEventSource { if (line == null) { return i; } - line.trim(); + line = line.trim(); processLine(line); } return MAX_ONE_TIME_READS; @@ -262,7 +262,7 @@ public class MonkeySourceScript implements MonkeyEventSource { if (line == null) { return 0; } - line.trim(); + line = line.trim(); processLine(line); return 1; } diff --git a/samples/ApiDemos/src/com/example/android/apis/media/projection/MediaProjectionDemo.java b/samples/ApiDemos/src/com/example/android/apis/media/projection/MediaProjectionDemo.java index 5cf6d6dee..b43b07eaf 100644 --- a/samples/ApiDemos/src/com/example/android/apis/media/projection/MediaProjectionDemo.java +++ b/samples/ApiDemos/src/com/example/android/apis/media/projection/MediaProjectionDemo.java @@ -40,18 +40,17 @@ import android.widget.Spinner; import android.widget.Toast; import android.widget.ToggleButton; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class MediaProjectionDemo extends Activity { private static final String TAG = "MediaProjectionDemo"; private static final int PERMISSION_CODE = 1; - private static final List RESOLUTIONS = new ArrayList() {{ - add(new Resolution(640,360)); - add(new Resolution(960,540)); - add(new Resolution(1366,768)); - add(new Resolution(1600,900)); - }}; + private static final List RESOLUTIONS = Arrays.asList( + new Resolution(640,360), + new Resolution(960,540), + new Resolution(1366,768), + new Resolution(1600,900)); private int mScreenDensity; private MediaProjectionManager mProjectionManager; diff --git a/samples/ApiDemos/src/com/example/android/mmslib/pdu/EncodedStringValue.java b/samples/ApiDemos/src/com/example/android/mmslib/pdu/EncodedStringValue.java index 1daec34b6..6442a743a 100644 --- a/samples/ApiDemos/src/com/example/android/mmslib/pdu/EncodedStringValue.java +++ b/samples/ApiDemos/src/com/example/android/mmslib/pdu/EncodedStringValue.java @@ -188,7 +188,6 @@ public class EncodedStringValue implements Cloneable { */ @Override public Object clone() throws CloneNotSupportedException { - super.clone(); int len = mData.length; byte[] dstBytes = new byte[len]; System.arraycopy(mData, 0, dstBytes, 0, len);