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

compiler mis-casts and erroneously compiles a char parameter to int

XMLWordPrintable

      FULL PRODUCT VERSION :
      openjdk version "1.8.0_102"
      OpenJDK Runtime Environment (build 1.8.0_102-b14)
      OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux rainbow 4.7.5-200.fc24.x86_64 #1 SMP Mon Sep 26 21:25:47 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Code problem found elsewhere and took a long time to fine with debugger, but distilled to the included source code:



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile and run TestChar above


      javac TestChar
      java TestChar

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      This should fail to compile and NOT cast a char value as an int.
      ACTUAL -
      Type is int: 97


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class TestChar {

        public TestChar() { }

        public void test(String bla, int value) {
          System.out.println("Type is int: " + value);
        }

        public static void main(String args[]) {
          TestChar t= new TestChar();
          t.test("xxx", 'a'); // this statement should not compile and wreaks havoc if it does
          t= null;
        }

      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I believe this code was working right in Java 7 and before (sorry, but not sure or I would have posted above). The problem reared it's head in some strange code. We changed a lot of code to use Enums and EnumLists to get around this.

            aroy Abhijit Roy (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: