From ebe28b025439060638de5acf4032b8a64d7b69ac Mon Sep 17 00:00:00 2001 From: Orion Hodson Date: Wed, 14 Sep 2022 09:46:56 +0100 Subject: [PATCH] Prefer valueOf() to boxed primitive constructors Constructors for boxed primitives (Byte, Short, Integer, etc) have long been deprecated. The preferred pattern is to use valueOf(). d8 fails to convert these instances in TypedProperties, most likely due to the method complexity. Bug: N/A Test: Treehugger Change-Id: Ib58ecc853e2bd1e5d53e9ec256ef0467aa051d9f --- .../internal/util/TypedProperties.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/core/java/com/android/internal/util/TypedProperties.java b/core/java/com/android/internal/util/TypedProperties.java index 5613999ea7738..c10dbe7fdf3bb 100644 --- a/core/java/com/android/internal/util/TypedProperties.java +++ b/core/java/com/android/internal/util/TypedProperties.java @@ -264,29 +264,29 @@ public class TypedProperties extends HashMap { // Ensure that the type can hold this value, and return. int width = (type >> 8) & 0xff; switch (width) { - case 1: - if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { - throw new ParseException(st, "8-bit integer constant"); - } - return new Byte((byte)value); - case 2: - if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { - throw new ParseException(st, "16-bit integer constant"); - } - return new Short((short)value); - case 4: - if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { - throw new ParseException(st, "32-bit integer constant"); - } - return new Integer((int)value); - case 8: - if (value < Long.MIN_VALUE || value > Long.MAX_VALUE) { - throw new ParseException(st, "64-bit integer constant"); - } - return new Long(value); - default: - throw new IllegalStateException( - "Internal error; unexpected integer type width " + width); + case 1: + if (value < Byte.MIN_VALUE || value > Byte.MAX_VALUE) { + throw new ParseException(st, "8-bit integer constant"); + } + return Byte.valueOf((byte) value); + case 2: + if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) { + throw new ParseException(st, "16-bit integer constant"); + } + return Short.valueOf((short) value); + case 4: + if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) { + throw new ParseException(st, "32-bit integer constant"); + } + return Integer.valueOf((int) value); + case 8: + if (value < Long.MIN_VALUE || value > Long.MAX_VALUE) { + throw new ParseException(st, "64-bit integer constant"); + } + return Long.valueOf(value); + default: + throw new IllegalStateException( + "Internal error; unexpected integer type width " + width); } } else if ((type & 0xff) == 'F') { if (token != StreamTokenizer.TT_WORD) { @@ -317,10 +317,10 @@ public class TypedProperties extends HashMap { throw new ParseException(st, "32-bit float constant"); } } - return new Float((float)value); + return Float.valueOf((float) value); } else { // This property is a double; no need to truncate. - return new Double(value); + return Double.valueOf(value); } } else if (type == TYPE_STRING) { // Expect a quoted string or the word "null".