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

BootstrapMethodError when capturing constructor ref to local classes

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 8
    • 8, 8-repo-lambda
    • core-libs
    • b89
    • generic
    • generic
    • Verified

      When capturing a constructor ref to a local class, as in this example from java.util.stream.MatchOps:

          public static TerminalOp<Long, Boolean> makeLong(LongPredicate predicate, MatchKind matchKind) {
              class MatchSink extends BooleanTerminalSink<Long> implements Sink.OfLong {

                  MatchSink() {
                      super(matchKind);
                  }

                  @Override
                  public void accept(long t) {
                  }
              }

              return new MatchOp<>(StreamShape.LONG_VALUE, matchKind, MatchSink::new);
          }

      Capture fails at runtime with a BootstrapMethodError that ultimately is caused by:

      Caused by: java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method newinvokespecial java.util.stream.MatchOps$1MatchSink.<init>:(MatchKind,Predicate)void; 0 captured parameters, 0 functional interface method parameters, 2 implementation parameters
          at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:189)
          at java.lang.invoke.LambdaMetafactory.metaFactory(LambdaMetafactory.java:190)
          at java.lang.invoke.CallSite.makeSite(CallSite.java:283)
          ... 23 more
      ]]>

            rfield Robert Field (Inactive)
            briangoetz Brian Goetz
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: