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

using method reference throws java.lang.BootstrapMethodError

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8u221
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      OS: windows 10
      JDK versions: 1.8.0_221, 1.8.0_131

      A DESCRIPTION OF THE PROBLEM :
      When using Generic type that implements two interfaces, if we use Method reference for method from the second interface java.lang.BootstrapMethodError will be thrown.

      In the code example we have two classes, if use method reference for the first interface everything works.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run main of the following class:


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      23 is printed twice.
      ACTUAL -
      works.printNumber(); //prints 23
      fail.printNumber(); //throws: java.lang.BootstrapMethodError: call site initialization exception

      ---------- BEGIN SOURCE ----------
      public class MethodRefBug {

          interface HasInteger {
              Integer getNum();
          }

          interface HasString {
              String getText();
          }

          static class TextAndNumber implements HasInteger, HasString {

              @Override
              public Integer getNum() {
                  return 22;
              }

              @Override
              public String getText() {
                  return "myText";
              }
          }

          static class ThrowExceptionClass<T extends HasString & HasInteger> {
              private final T t;

              ThrowExceptionClass(T t) {
                  this.t = t;
              }

              void printNumber() {
                  Supplier<Integer> numSupplier = t::getNum;
                  System.out.println("numSupplier = " + numSupplier.get());
              }
          }

          static class Working<T extends HasInteger & HasString> {
              private final T t;

              Working(T t) {
                  this.t = t;
              }

              void printNumber() {
                  Supplier<Integer> numSupplier = t::getNum;
                  System.out.println("numSupplier = " + numSupplier.get());
              }
          }

          public static void main(String[] args) {
              Working<TextAndNumber> works = new Working<>(new TextAndNumber());
              works.printNumber(); //prints 22
              ThrowExceptionClass<TextAndNumber> fail = new ThrowExceptionClass<>(new TextAndNumber());
              fail.printNumber(); //throws: java.lang.BootstrapMethodError: call site initialization exception
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      use lambda expression instead of method reference

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              psonal Pallavi Sonal (Inactive)
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: