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

Incorrect code generated for unary - on char operand

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 19
    • 11, 17, 18, 19
    • tools
    • None
    • b07

      (Reported by Kristian Thomassen.)

      Consider code like:
      ---
      public class UnaryMinus {
          public static void main(String... args) {
              Character var = (char) - (false ? (char) args.length : (char) 2);
          }
      }
      ---

      When run, this will cause a crash:
      ---
      $ java UnaryMinus.java
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -2 out of bounds for length 128
              at java.base/java.lang.Character.valueOf(Character.java:8595)
              at UnaryMinus.main(UnaryMinus.java:3)
      ---

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: