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

Inference with wildcard types causes selection of inapplicable method

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 6u10, 6u23, 7
    • Fix Version/s: 7
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b64
    • CPU:
      generic, x86
    • OS:
      generic, windows_xp
    • Verification:
      Verified

      Backports

        Description

        From Neal Gafter:

        The following demonstrates a bug in javac's handling of wildcard types that results in a hole in the type system. javac accepts this program without even a warning but it blows up with a class cast error at runtime. The Java compiler for Eclipse rejects this code.

        import java.util.*;

        class Comp {
          static <T> Comparator<T> compound(final Iterable<? extends Comparator<? super T>> it) {
            return new Comparator<T>() {
              public int compare(T t1, T t2) {
                for (Comparator<? super T> c : it) {
                  int r = c.compare(t1, t2);
                  if (r != 0) return r;
                }
                return 0;
              }
            };
          }
          public static void main(String[] args) {
            List<Comparator<?>> x = new ArrayList<Comparator<?>>();
            Comparator<Integer> c1 = new Comparator<Integer>() {
              public int compare(Integer i1, Integer i2) {
                return i1.compareTo(i2);
              }
            };
            x.add(c1);
            x.add(String.CASE_INSENSITIVE_ORDER);
            Comparator<String> c3 = compound(x);
            c3.compare("foo", "bar");
          }
        }

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                jjg Jonathan Gibbons
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: