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

Jshell: error with mutually dependent snippets, when one must be replaced

XMLWordPrintable

    • b116
    • 9
    • b36
    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "9"
      Java(TM) SE Runtime Environment (build 9+181)
      Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux mathisubuntu 4.10.0-35-generic #39~16.04.1-Ubuntu SMP Wed Sep 13 09:02:42 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      In jshell (works fine in normal java code)
      a
        class A<T>
      has a method of return type Supplier<T> and any nested class (required!). It returns an instance of a
        class B<T> implements Supplier<T>
      using the constructor
        public B(A<T> a) [...]
      thus inferring the type.
      When attempting to instanciate A (attempting to load it), it says "A<T> cannot be converted to A<T>"

      (PS: there is no specific bug report option for jshell, so I assumed "multiple applications" reports would be redirected anyways)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Take the code included in this report. Copy it into a file
      2) open it in jshell using /open [filename] or jshell [filename]
      3) try to do new A()

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      a new instance of A is created without error, as it happens when run via normal javac + java.

      ACTUAL -
      When, and >only< when A has a nested class (here SomeClass) the following error occurs:
      | Error:
      | cannot infer type arguments for B<>
      | reason: cannot infer type-variable(s) T
      | (argument mismatch; A<T> cannot be converted to A<T>)
      | return new B<>(this);
      | ^-----------^

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      | Error:
      | cannot infer type arguments for B<>
      | reason: cannot infer type-variable(s) T
      | (argument mismatch; A<T> cannot be converted to A<T>)
      | return new B<>(this);
      | ^-----------^

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.function.Supplier;

      public class A <T> {
        private class SomeClass { //error only occurs when this is present

        }
        public Supplier<T> m1() {
          return new B<>(this);
        }
      }

      public class B <T> implements Supplier<T> {
        public B(A<T> a) {

        }

        private class D {} //does not influence result

        public T get() {return null;}
      }
      ---------- END SOURCE ----------

        1. A.java
          0.4 kB
          Fairoz Matte

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

              Created:
              Updated:
              Resolved: