A boxing cast applied to a unary (plus or minus) expression does not parse as expected.

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      The disambiguation procedure for the nesting of casts and other unary expressions in the Java Language Specification (§15.15) is inconsistent. The given rationale ...

      "The result of the + operator must be numeric, and all type names involved in casts on numeric values are known keywords. Thus, if p is a keyword naming a primitive type, then (p)+q can make sense only as a cast of a unary expression. However, if p is not a keyword naming a primitive type, then (p)+q can make sense only as a binary arithmetic operation. Similar remarks apply to the - operator."

      ... makes a wrong assumption: A casting context (§5.5) can entail a boxing conversion (§5.1.7), hence a cast of a numeric value to a (corresponding) reference type is quite possible.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the source code.

      ---------- BEGIN SOURCE ----------
      class Bug {
          static final int M = (int)-1;
          static final Integer N = (Integer)-1;
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Add parentheses in affected code.

      FREQUENCY :
      ALWAYS

            Assignee:
            Unassigned
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: