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

Compilation failed: internal java compiler error if lambda doesn't specify type

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: P3 P3
    • 8
    • 8
    • tools
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0-ea"
      Java(TM) SE Runtime Environment (build 1.8.0-ea-b98)
      Java HotSpot(TM) 64-Bit Server VM (build 25.0-b40, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      compiler internal error when passing a lambda to a method without explicitly parameter type

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
       @Test
          public void test() {
              String word = "Hello world!";
              assertThat(bind(Optional.of(word), optional -> Optional.of(optional.get().length())), is(Optional.of(12)));
          }


          private <V, R> Optional<R> bind(Optional<V> optional, Function<Optional<V>, Optional<R>> function) {
              return function.apply(optional);
          }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
       Compilation completed without error
      ACTUAL -
      java: An exception has occurred in the compiler (1.8.0-ea). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
        @Test
          public void test() {
              String word = "Hello world!";
              assertThat(bind(Optional.of(word), optional -> Optional.of(optional.get().length())), is(Optional.of(12)));
          }


          private <V, R> Optional<R> bind(Optional<V> optional, Function<Optional<V>, Optional<R>> function) {
              return function.apply(optional);
          }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
       @Test
          public void test() {
              String word = "Hello world!";
             // assertThat(bind(Optional.of(word), optional -> Optional.of(optional.get().length())), is(Optional.of(12)));
              assertThat(bind(Optional.of(word), (Optional<String> optional) -> Optional.of(optional.get().length())), is(Optional.of(12)));
          }

      SUPPORT :
      YES

            vromero Vicente Arturo Romero Zaldivar
            rcalnan Roger Calnan
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: