Skip to content

Commit

Permalink
8286378: Address possibly lossy conversions in java.base
Browse files Browse the repository at this point in the history
Reviewed-by: naoto, xuelei, bpb, alanb
  • Loading branch information
Roger Riggs committed May 12, 2022
1 parent 0a6832b commit 17c5278
Show file tree
Hide file tree
Showing 32 changed files with 68 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected int doSelect(Consumer<SelectionKey> action, long timeout)
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private static final int[] expandToSubKey(int[][] kr, boolean decrypting) {
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]);
}
}
}
Expand All @@ -227,7 +227,7 @@ private static final int[] expandToSubKey(int[][] kr, boolean decrypting) {
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;
}
Expand Down Expand Up @@ -276,7 +276,7 @@ private static final int[] expandToSubKey(int[][] kr, boolean decrypting) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ private void setRSVals() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ private long implSkip(long n) throws IOException {
}

long skipped = (avail < n) ? avail : n;
pos += skipped;
pos += (int)skipped;
return skipped;
}

Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/io/BufferedReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ private long implSkip(long n) throws IOException {
}
long d = nChars - nextChar;
if (r <= d) {
nextChar += r;
nextChar += (int)r;
r = 0;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/io/ByteArrayInputStream.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -228,7 +228,7 @@ public synchronized long skip(long n) {
k = n < 0 ? 0 : n;
}

pos += k;
pos += (int) k;
return k;
}

Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/io/CharArrayReader.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -196,7 +196,7 @@ public long skip(long n) throws IOException {
if (n < 0) {
return 0;
}
pos += n;
pos += (int) n;
return n;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public long skip(long n) throws IOException {
if (n < pskip) {
pskip = n;
}
pos += pskip;
pos += (int) pskip;
n -= pskip;
}
if (n > 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/io/PushbackReader.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -251,7 +251,7 @@ public long skip(long n) throws IOException {
int avail = buf.length - pos;
if (avail > 0) {
if (n <= avail) {
pos += n;
pos += (int)n;
return n;
} else {
pos = buf.length;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -145,7 +145,7 @@ public synchronized long skip(long n) {
if (n > count - pos) {
n = count - pos;
}
pos += n;
pos += (int) n;
return n;
}

Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/io/StringReader.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -136,7 +136,7 @@ public long skip(long n) throws IOException {
// 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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/math/BigInteger.java
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ private static byte[] randomBits(int numBits, Random rnd) {
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;
}
Expand Down Expand Up @@ -3389,7 +3389,7 @@ private BigInteger mod2(int p) {

// 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));
}
Expand Down
6 changes: 3 additions & 3 deletions src/java.base/share/classes/java/net/URLPermission.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -418,7 +418,7 @@ private List<String> normalizeMethods(String methods) {
"White space not allowed in methods: \"" + methods + "\"");
} else {
if (c >= 'a' && c <= 'z') {
c += 'A' - 'a';
c += (char) ('A' - 'a');
}
b.append(c);
}
Expand All @@ -437,7 +437,7 @@ private List<String> normalizeHeaders(String headers) {
char c = headers.charAt(i);
if (c >= 'a' && c <= 'z') {
if (capitalizeNext) {
c += 'A' - 'a';
c += (char) ('A' - 'a');
capitalizeNext = false;
}
b.append(c);
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/text/DecimalFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ private void localizeDigits(char[] digitsBuffer) {
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.
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/time/Duration.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -283,7 +283,7 @@ public static Duration ofNanos(long nanos) {
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -351,7 +351,7 @@ public static TemporalAdjuster dayOfWeekInMonth(int ordinal, DayOfWeek dayOfWeek
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 {
Expand All @@ -360,7 +360,7 @@ public static TemporalAdjuster dayOfWeekInMonth(int ordinal, DayOfWeek dayOfWeek
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);
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/java.base/share/classes/java/util/GregorianCalendar.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -2323,11 +2323,11 @@ private int computeFields(int fieldMask, int tzMask) {
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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1607,11 +1607,11 @@ private int computeFields(int fieldMask, int tzMask) {
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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/util/UUID.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static UUID randomUUID() {
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);
}

Expand All @@ -176,7 +176,7 @@ public static UUID nameUUIDFromBytes(byte[] name) {
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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/classes/java/util/jar/Manifest.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -533,7 +533,7 @@ public long skip(long n) throws IOException {
if (n > avail) {
n = avail;
}
pos += n;
pos += (int) n;
return n;
}

Expand Down
8 changes: 4 additions & 4 deletions src/java.base/share/classes/java/util/stream/Nodes.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -2055,14 +2055,14 @@ public void compute() {
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));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public long skip(long n) throws IOException {
if (n < 0) {
return 0;
}
ostart += n;
ostart += (int) n;
return n;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -834,7 +834,7 @@ static int estimateDecExp(long fractBits, int binExp) {
}
}

private static int insignificantDigits(int insignificant) {
private static int insignificantDigits(long insignificant) {
int i;
for ( i = 0; insignificant >= 10L; i++ ) {
insignificant /= 10L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,11 @@ private int pop() {
*/
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;
}
}
Expand Down Expand Up @@ -1503,4 +1503,3 @@ static void putAbstractType(
}
}
}

Loading

1 comment on commit 17c5278

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.