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

javac compiler does not detect unchecked cast

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8
    • tools
    • x86
    • os_x

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      Compiling the provided java snippet should yield a unchecked cast warning

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile code code using javac

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      unchecked cast warning
      ACTUAL -
      no warning

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package a;

      public class CastTest {
      public interface BaseInterface<T> {

      }

      public interface SubInterfaceA<T> extends BaseInterface<T> {

      }

      public interface SubInterfaceB<T> extends BaseInterface<T> {

      }

      public static void main(String[] args) {
      SubInterfaceA<String> a = null;
      SubInterfaceB<String> b = (SubInterfaceB<String>) a; // javac does not warn
      b = (SubInterfaceB<String>)(BaseInterface<String>)a;

      }
      }
      ---------- END SOURCE ----------

      also discussed in compiler-dev: http://mail.openjdk.java.net/pipermail/compiler-dev/2014-May/008747.html

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

              Created:
              Updated: