FULL PRODUCT VERSION :
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
windows 8
windows xp
CentOS release 6.6 (Final)
A DESCRIPTION OF THE PROBLEM :
Byte.valueOf() cause bitwise operators got wrong result
REGRESSION. Last worked in version 8u11
ADDITIONAL REGRESSION INFORMATION:
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
with -server option to run the code
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test {
public static void main(String[] args) throws Exception {
for (int i = 0, k = 20; i < Integer.MAX_VALUE; i++) {
final Byte b = (byte) -1; // new Byte((byte) -1) won't work
final int x = b.byteValue() & 0xff;
if (i % 100 == 0) Thread.sleep(1); // or other operations to make this code run slower
if (x == -1) System.out.println(x + " is -1 (" + i + ")"); // never happened
if (x != 255) {
System.out.println(x + " is not 255 (" + i + ")");
if (x == -1) System.out.println(x + " is not 255 but -1 (" + i + ")"); // only once
if (--k == 0) break; // change k value if you want more samples
}
}
}
}
---------- END SOURCE ----------