--- old/src/share/classes/java/lang/Integer.java 2013-02-13 14:40:47.898113052 -0800 +++ new/src/share/classes/java/lang/Integer.java 2013-02-13 14:40:47.662113041 -0800 @@ -26,7 +26,6 @@ package java.lang; import java.lang.annotation.Native; -import java.util.Properties; /** * The {@code Integer} class wraps a value of the primitive type @@ -185,7 +184,7 @@ * @since 1.8 */ public static String toUnsignedString(int i, int radix) { - return Long.toString(toUnsignedLong(i), radix); + return Long.toUnsignedString(toUnsignedLong(i), radix); } /** @@ -308,8 +307,11 @@ * Convert the integer to an unsigned number. */ private static String toUnsignedString0(int i, int shift) { - char[] buf = new char[32]; - int charPos = 32; + // assert shift > 0 && shift <=5 : "Illegal shift value"; + int mag = Integer.SIZE - Integer.numberOfLeadingZeros(i); + int chars = Math.max(((mag + (shift - 1)) / shift), 1); + char[] buf = new char[chars]; + int charPos = chars; int radix = 1 << shift; int mask = radix - 1; do { @@ -317,7 +319,8 @@ i >>>= shift; } while (i != 0); - return new String(buf, charPos, (32 - charPos)); + // Use special constructor which takes over "buf". + return new String(buf, true); } @@ -875,6 +878,7 @@ * Returns the value of this {@code Integer} as a {@code long} * after a widening primitive conversion. * @jls 5.1.2 Widening Primitive Conversions + * @see Integer#toUnsignedLong(int) */ public long longValue() { return (long)value;