Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 11
    • Fix Version/s: tbd_major
    • Component/s: tools
    • Labels:
      None

      Description

      I think this is probably a duplicate of JDK-8054941, but it might be useful as another test case. This one doesn't involve lower bounds, or `null`.

      The following program contains no casts and compiles cleanly with -Xlint:unchecked,rawtypes, but fails at runtime with a CCE:

      ```
      abstract class T {

        public static void main(String[] args) {
          Box<String> a = new Box<>("hello");
          Box<Object> b = cast(a);
          b.set(42);
          System.err.println(a.get());
        }

        static class Box<T> {
          private T x;
          Box(T x) { this.x = x; }
          T get() { return x; }
          void set(T x) { this.x = x; }
        }

        static Box<Object> cast(Box<String> target) {
          return identity(flatten(new Box<Box<?>>(target)));
        }

        static <A> A identity(A x) {
          return x;
        }

        static <B> Box<? extends B> flatten(Box<Box<? extends B>> r) {
          return r.get();
        }
      }
      ```

      ```
      $ javac -fullversion
      javac full version "11-ea+13"
      $ javac -Xlint:all T.java
      $ java T
      ...
      Exception in thread "main" java.lang.ClassCastException: java.base/java.lang.Integer cannot be cast to java.base/java.lang.String
      at T.main(JavacBug.java:7)
      ```

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vromero Vicente Arturo Romero Zaldivar
                Reporter:
                cushon Liam Miller-Cushon
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: