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

Correct Java code compiles, but fails at runtime with BootstrapMethodError

XMLWordPrintable

    • 9
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Intersection types and different order of supertypes in type parameters cause incorrect bootstrap method parameters generated.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and execute the provided code example.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Code compiles without errors and prints "null" (or a compilation error is reported).
      ACTUAL -
      Exception in thread "main" java.lang.BootstrapMethodError: bootstrap method initialization exception
      at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:194)
      at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:307)
      at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:258)
      at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:248)
      at j.Test.test(Test.java:23)
      at j.Test.main(Test.java:27)
      Caused by: java.lang.invoke.LambdaConversionException: Type mismatch for instantiated parameter 0: interface j.Test$X is not a subtype of interface j.Test$Y
      at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.checkDescriptor(AbstractValidatingLambdaMetafactory.java:308)
      at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:294)
      at java.base/java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:328)
      at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:127)
      ... 5 more


      ---------- BEGIN SOURCE ----------
      package j;

      public class Test {
          interface X {}
          interface Y {}

          interface A extends X, Y {}
          interface B extends X, Y {}

          interface IFoo<T extends Y & X> {
              void foo(T x);
          }

          static <T> T sel(T a, T b) { return a; }

          static class G<T extends X & Y> {
              void check(IFoo<? extends T> foo) {
                  foo.foo(null);
              }
          }

          static void test(G<A> ga, G<B> gb) {
              sel(ga, gb).check(v -> System.out.println(v));
          }

          public static void main(String[] args) {
              test(new G<>(), new G<>());
          }
      }

      ---------- END SOURCE ----------

      FREQUENCY : always


            vromero Vicente Arturo Romero Zaldivar
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: