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

javac, spurious warning for instanceof operator

XMLWordPrintable

    • b01
    • x86
    • windows_7

        Attach a testcase for a compiler bug in JDK 7 update 51 and 7u60 that is probably a regression. However it works fine with JDK 8 latest build 124.

        The compiler issues the following warnings:

        -----------------
        C:\Users\Gili\Documents\NetBeansProjects\UncheckedCast\src\uncheckedcast\NumberPreconditions.java:38: warning: [unchecked] unchecked cast
                if (parameter instanceof BigDecimal) {
          required: BigDecimal
          found: T
          where T is a type-variable:
            T extends Number,Comparable<? super T> declared in class NumberPreconditions
        C:\Users\Gili\Documents\NetBeansProjects\UncheckedCast\src\uncheckedcast\NumberPreconditions.java:40: warning: [unchecked] unchecked cast
                    BigDecimal decimal = (BigDecimal) parameter;
          required: BigDecimal
          found: T
          where T is a type-variable:
            T extends Number,Comparable<? super T> declared in class NumberPreconditions
        2 warnings
        -----------------

        It's flagging "instanceof" as an unchecked cast, which is nonsense since "instanceof" does not do any casting. Another thing to notice is that this bug only occurs if NumberPreconditions extends Preconditions. Meaning, you must use class inheritance for this bug to occur. If you merge the two classes into one, the warning goes away.

        Please mark this as a CAP issue.

        Priority justification:
        Impact: Medium impact, regression
        Likelhood: Medium,intermittent
        Workaround: Medium, unknown

        ILW = MMM => P3

              vromero Vicente Arturo Romero Zaldivar
              tyao Ting-Yun Ingrid Yao (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: