8286378: Address possibly lossy conversions in java.base

Reviewed-by: naoto, xuelei, bpb, alanb
This commit is contained in:
Roger Riggs 2022-05-12 16:50:36 +00:00
parent 0a6832b24c
commit 17c52789b7
32 changed files with 68 additions and 71 deletions

@ -125,7 +125,7 @@ class EPollSelectorImpl extends SelectorImpl {
if (numEntries == IOStatus.INTERRUPTED && timedPoll) {
// timed poll interrupted so need to adjust timeout
long adjust = System.nanoTime() - startTime;
to -= TimeUnit.MILLISECONDS.convert(adjust, TimeUnit.NANOSECONDS);
to =- (int) TimeUnit.NANOSECONDS.toMillis(adjust);
if (to <= 0) {
// timeout expired so no retry
numEntries = 0;

@ -217,7 +217,7 @@ final class AESCrypt extends SymmetricCipher implements AESConstants
for (t = 0; t < 8; t++) {
cox[i][t] = B[t];
for (j = 0; j < 8; j++) {
cox[i][t] ^= A[t][j] * box[i][j];
cox[i][t] ^= (byte)(A[t][j] * box[i][j]);
}
}
}
@ -227,7 +227,7 @@ final class AESCrypt extends SymmetricCipher implements AESConstants
for (i = 0; i < 256; i++) {
S[i] = (byte)(cox[i][0] << 7);
for (t = 1; t < 8; t++) {
S[i] ^= cox[i][t] << (7-t);
S[i] ^= (byte)(cox[i][t] << (7-t));
}
Si[S[i] & 0xFF] = (byte) i;
}
@ -276,7 +276,7 @@ final class AESCrypt extends SymmetricCipher implements AESConstants
for (t = 0; t < 4; t++) {
if (i != t) {
for (j = i+1; j < 8; j++) {
AA[t][j] ^= mul(AA[i][j], AA[t][i]);
AA[t][j] ^= (byte)(mul(AA[i][j], AA[t][i]));
}
AA[t][i] = 0;
}

@ -246,9 +246,9 @@ final class Poly1305 {
keyBytes[7] &= 15;
keyBytes[11] &= 15;
keyBytes[15] &= 15;
keyBytes[4] &= 252;
keyBytes[8] &= 252;
keyBytes[12] &= 252;
keyBytes[4] &= (byte)252;
keyBytes[8] &= (byte)252;
keyBytes[12] &= (byte)252;
// Create IntegerModuloP elements from the r and s values
r = ipl1305.getElement(keyBytes, 0, RS_LENGTH, (byte)0);

@ -436,7 +436,7 @@ public class BufferedInputStream extends FilterInputStream {
}
long skipped = (avail < n) ? avail : n;
pos += skipped;
pos += (int)skipped;
return skipped;
}

@ -475,7 +475,7 @@ public class BufferedReader extends Reader {
}
long d = nChars - nextChar;
if (r <= d) {
nextChar += r;
nextChar += (int)r;
r = 0;
break;
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1994, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -228,7 +228,7 @@ public class ByteArrayInputStream extends InputStream {
k = n < 0 ? 0 : n;
}
pos += k;
pos += (int) k;
return k;
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -196,7 +196,7 @@ public class CharArrayReader extends Reader {
if (n < 0) {
return 0;
}
pos += n;
pos += (int) n;
return n;
}
}

@ -323,7 +323,7 @@ public class PushbackInputStream extends FilterInputStream {
if (n < pskip) {
pskip = n;
}
pos += pskip;
pos += (int) pskip;
n -= pskip;
}
if (n > 0) {

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -251,7 +251,7 @@ public class PushbackReader extends FilterReader {
int avail = buf.length - pos;
if (avail > 0) {
if (n <= avail) {
pos += n;
pos += (int)n;
return n;
} else {
pos = buf.length;

@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -145,7 +145,7 @@ public class StringBufferInputStream extends InputStream {
if (n > count - pos) {
n = count - pos;
}
pos += n;
pos += (int) n;
return n;
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -136,7 +136,7 @@ public class StringReader extends Reader {
// Bound skip by beginning and end of the source
long r = Math.min(length - next, n);
r = Math.max(-next, r);
next += r;
next += (int)r;
return r;
}
}

@ -720,7 +720,7 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
if (numBytes > 0) {
rnd.nextBytes(randomBits);
int excessBits = 8*numBytes - numBits;
randomBits[0] &= (1 << (8-excessBits)) - 1;
randomBits[0] &= (byte)((1 << (8-excessBits)) - 1);
}
return randomBits;
}
@ -3389,7 +3389,7 @@ public class BigInteger extends Number implements Comparable<BigInteger> {
// Mask out any excess bits
int excessBits = (numInts << 5) - p;
mag[0] &= (1L << (32-excessBits)) - 1;
mag[0] &= (int)((1L << (32-excessBits)) - 1);
return (mag[0] == 0 ? new BigInteger(1, mag) : new BigInteger(mag, 1));
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -418,7 +418,7 @@ public final class URLPermission extends Permission {
"White space not allowed in methods: \"" + methods + "\"");
} else {
if (c >= 'a' && c <= 'z') {
c += 'A' - 'a';
c += (char) ('A' - 'a');
}
b.append(c);
}
@ -437,7 +437,7 @@ public final class URLPermission extends Permission {
char c = headers.charAt(i);
if (c >= 'a' && c <= 'z') {
if (capitalizeNext) {
c += 'A' - 'a';
c += (char) ('A' - 'a');
capitalizeNext = false;
}
b.append(c);

@ -1532,7 +1532,7 @@ public class DecimalFormat extends NumberFormat {
cursor--) {
if (digitsCounter != 0) {
// This is a digit char, we must localize it.
digitsBuffer[cursor] += fastPathData.zeroDelta;
digitsBuffer[cursor] += (char)fastPathData.zeroDelta;
digitsCounter--;
} else {
// Decimal separator or grouping char. Reinit counter only.

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -283,7 +283,7 @@ public final class Duration
long secs = nanos / NANOS_PER_SECOND;
int nos = (int) (nanos % NANOS_PER_SECOND);
if (nos < 0) {
nos += NANOS_PER_SECOND;
nos += (int) NANOS_PER_SECOND;
secs--;
}
return create(secs, nos);

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -351,7 +351,7 @@ public final class TemporalAdjusters {
Temporal temp = temporal.with(DAY_OF_MONTH, 1);
int curDow = temp.get(DAY_OF_WEEK);
int dowDiff = (dowValue - curDow + 7) % 7;
dowDiff += (ordinal - 1L) * 7L; // safe from overflow
dowDiff += (int) ((ordinal - 1L) * 7L); // safe from overflow
return temp.plus(dowDiff, DAYS);
};
} else {
@ -360,7 +360,7 @@ public final class TemporalAdjusters {
int curDow = temp.get(DAY_OF_WEEK);
int daysDiff = dowValue - curDow;
daysDiff = (daysDiff == 0 ? 0 : (daysDiff > 0 ? daysDiff - 7 : daysDiff));
daysDiff -= (-ordinal - 1L) * 7L; // safe from overflow
daysDiff -= (int) ((-ordinal - 1L) * 7L); // safe from overflow
return temp.plus(daysDiff, DAYS);
};
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -2323,11 +2323,11 @@ public class GregorianCalendar extends Calendar {
fixedDate += time / ONE_DAY;
timeOfDay += (int) (time % ONE_DAY);
if (timeOfDay >= ONE_DAY) {
timeOfDay -= ONE_DAY;
timeOfDay -= (int)ONE_DAY;
++fixedDate;
} else {
while (timeOfDay < 0) {
timeOfDay += ONE_DAY;
timeOfDay += (int)ONE_DAY;
--fixedDate;
}
}

@ -1607,11 +1607,11 @@ class JapaneseImperialCalendar extends Calendar {
fixedDate += time / ONE_DAY;
timeOfDay += (int) (time % ONE_DAY);
if (timeOfDay >= ONE_DAY) {
timeOfDay -= ONE_DAY;
timeOfDay -= (int) ONE_DAY;
++fixedDate;
} else {
while (timeOfDay < 0) {
timeOfDay += ONE_DAY;
timeOfDay += (int) ONE_DAY;
--fixedDate;
}
}

@ -152,7 +152,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID> {
randomBytes[6] &= 0x0f; /* clear version */
randomBytes[6] |= 0x40; /* set to version 4 */
randomBytes[8] &= 0x3f; /* clear variant */
randomBytes[8] |= 0x80; /* set to IETF variant */
randomBytes[8] |= (byte) 0x80; /* set to IETF variant */
return new UUID(randomBytes);
}
@ -176,7 +176,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID> {
md5Bytes[6] &= 0x0f; /* clear version */
md5Bytes[6] |= 0x30; /* set to version 3 */
md5Bytes[8] &= 0x3f; /* clear variant */
md5Bytes[8] |= 0x80; /* set to IETF variant */
md5Bytes[8] |= (byte) 0x80; /* set to IETF variant */
return new UUID(md5Bytes);
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -533,7 +533,7 @@ public class Manifest implements Cloneable {
if (n > avail) {
n = avail;
}
pos += n;
pos += (int) n;
return n;
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -2055,14 +2055,14 @@ final class Nodes {
else {
task.setPendingCount(task.node.getChildCount() - 1);
int size = 0;
long size = 0;
int i = 0;
for (;i < task.node.getChildCount() - 1; i++) {
K leftTask = task.makeChild(i, task.offset + size);
K leftTask = task.makeChild(i, (int) (task.offset + size));
size += leftTask.node.count();
leftTask.fork();
}
task = task.makeChild(i, task.offset + size);
task = task.makeChild(i, (int) (task.offset + size));
}
}
}

@ -297,7 +297,7 @@ public class CipherInputStream extends FilterInputStream {
if (n < 0) {
return 0;
}
ostart += n;
ostart += (int) n;
return n;
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -834,7 +834,7 @@ public class FloatingDecimal{
}
}
private static int insignificantDigits(int insignificant) {
private static int insignificantDigits(long insignificant) {
int i;
for ( i = 0; insignificant >= 10L; i++ ) {
insignificant /= 10L;

@ -611,11 +611,11 @@ class Frame {
*/
private void pop(final int elements) {
if (outputStackTop >= elements) {
outputStackTop -= elements;
outputStackTop -= (short) elements;
} else {
// If the number of elements to be popped is greater than the number of elements in the output
// stack, clear it, and pop the remaining elements from the input stack.
outputStackStart -= elements - outputStackTop;
outputStackStart -= (short) (elements - outputStackTop);
outputStackTop = 0;
}
}
@ -1503,4 +1503,3 @@ class Frame {
}
}
}

@ -1244,7 +1244,7 @@ final class MethodWriter extends MethodVisitor {
// one place, but this does not work for labels which have not been visited yet.
// Therefore, when we detect here two labels having the same bytecode offset, we need to
// - consolidate the state scattered in these two instances into the canonical instance:
currentBasicBlock.flags |= (label.flags & Label.FLAG_JUMP_TARGET);
currentBasicBlock.flags |= (short) (label.flags & Label.FLAG_JUMP_TARGET);
// - make sure the two instances share the same Frame instance (the implementation of
// {@link Label#getCanonicalInstance} relies on this property; here label.frame should be
// null):
@ -1260,7 +1260,7 @@ final class MethodWriter extends MethodVisitor {
if (lastBasicBlock != null) {
if (label.bytecodeOffset == lastBasicBlock.bytecodeOffset) {
// Same comment as above.
lastBasicBlock.flags |= (label.flags & Label.FLAG_JUMP_TARGET);
lastBasicBlock.flags |= (short) (label.flags & Label.FLAG_JUMP_TARGET);
// Here label.frame should be null.
label.frame = lastBasicBlock.frame;
currentBasicBlock = lastBasicBlock;
@ -2424,4 +2424,3 @@ final class MethodWriter extends MethodVisitor {
attributePrototypes.addAttributes(firstCodeAttribute);
}
}

@ -4866,7 +4866,7 @@ public final class Main {
if (pos % 2 == 0) {
data[pos/2] = (byte)(hex << 4);
} else {
data[pos/2] += hex;
data[pos/2] += (byte)hex;
}
pos++;
}
@ -5338,4 +5338,3 @@ class Pair<A, B> {
return new Pair<>(a,b);
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -142,9 +142,9 @@ public class BitArray {
int bit = position(index);
if (value) {
repn[idx] |= bit;
repn[idx] |= (byte) bit;
} else {
repn[idx] &= ~bit;
repn[idx] &= (byte) ~bit;
}
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -717,7 +717,7 @@ public class DerValue {
byte[] retval = Arrays.copyOfRange(buffer, start + 1, end);
if (numOfPadBits != 0) {
// get rid of the padding bits
retval[end - start - 2] &= (0xff << numOfPadBits);
retval[end - start - 2] &= (byte)((0xff << numOfPadBits));
}
data.pos = data.end; // Compatibility. Reach end.
return retval;

@ -524,10 +524,10 @@ public final class ObjectIdentifier implements Serializable {
// and move them!
out[opos/ow] |= // paste!
(((in[ioffset+ipos/iw]+256) // locate the byte (+256 so that it's never negative)
(byte)((((in[ioffset+ipos/iw]+256) // locate the byte (+256 so that it's never negative)
>> (iw-ipos%iw-count)) & // move to the end of a byte
((1 << (count))-1)) // zero out all other bits
<< (ow-opos%ow-count); // move to the output position
<< (ow-opos%ow-count)); // move to the output position
ipos += count; // advance
opos += count; // advance
}
@ -551,7 +551,7 @@ public final class ObjectIdentifier implements Serializable {
if (pack[i] != 0) {
firstNonZero = i;
}
pack[i] |= 0x80;
pack[i] |= (byte)0x80;
}
System.arraycopy(pack, firstNonZero,
out, ooffset, pack.length-firstNonZero);

@ -420,8 +420,8 @@ public abstract sealed class IntegerPolynomial implements IntegerFieldModuloP
int bitsAdded = bitsPerLimb - bitPos;
int bitsLeft = 8 - bitsAdded;
dst[dstIndex] += (curLimbValue & (0xFF >> bitsAdded))
<< bitsAdded;
dst[dstIndex] += (byte) ((curLimbValue & (0xFF >> bitsAdded))
<< bitsAdded);
curLimbValue >>= bitsLeft;
bitPos = bitsLeft;
} else {

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -190,12 +190,12 @@ public final class ZoneInfoFile {
char[] buf = new char[] { 'G', 'M', 'T', sign, '0', '0', ':', '0', '0' };
if (hh >= 10) {
buf[4] += hh / 10;
buf[4] += (char)(hh / 10);
}
buf[5] += hh % 10;
buf[5] += (char)(hh % 10);
if (mm != 0) {
buf[7] += mm / 10;
buf[8] += mm % 10;
buf[7] += (char)(mm / 10);
buf[8] += (char)(mm % 10);
}
return new String(buf);
}

@ -120,7 +120,7 @@ class PollSelectorImpl extends SelectorImpl {
if (numPolled == IOStatus.INTERRUPTED && timedPoll) {
// timed poll interrupted so need to adjust timeout
long adjust = System.nanoTime() - startTime;
to -= TimeUnit.MILLISECONDS.convert(adjust, TimeUnit.NANOSECONDS);
to =- (int) TimeUnit.NANOSECONDS.toMillis(adjust);
if (to <= 0) {
// timeout expired so no retry
numPolled = 0;