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

Wrong overloaded method is resolved instead of reporting a type error

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 23.0.2
    • tools
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      javac -version
      javac 22

      A DESCRIPTION OF THE PROBLEM :
      The following program compiles, although there's a type error on line 11 when calling the <T> spliterator using a type argument of type String. The spliterator method expects something of type Iterator<? super String>, but the argument of this method has type PrimitiveIterator.OfInt.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      import java.util.*;

      public class Test {
          public static void main(String[] args) {
            List<Integer> lst = new LinkedList<>();
            lst.add(2);
            lst.add(1);
            lst.add(3);
            PrimitiveIterator.OfInt iterator = lst.stream().mapToInt(Integer::intValue).iterator();

            Spliterator.OfInt x = java.util.Spliterators.<String>spliterator(java.util.Spliterators.iterator(java.util.Spliterators.spliterator(iterator, 0, 2)), 0, 1);
            System.out.println(x.characteristics());
          }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The program should have been rejected with an error message of the form:

      Spliterator<String> was expected; but Spliterator.OfInt was found.
      ACTUAL -
      The compiler accepts the code.

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

              Created:
              Updated:
              Resolved: