Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8071865

Byte.valueOf() cause bitwise operators got wrong result

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • 8u40
    • 8u20, 8u25, 8u31
    • hotspot
    • generic
    • generic

      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 ----------

            thartmann Tobias Hartmann
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: