Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11385

reference to the constructor of an abstract class is not detected

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      import java.util.function.*;
      
      abstract class Foo {
        Foo(String x) {}
      }
      
      class Test {
        public static void main(String[] args) {
          Function<String, Foo> x = Foo::new;
          x.apply("d");
        }
      } 

      Actual behavior

      The program compiles but I get the following runtime exception, because I call the constructor of an abstract class.

      Exception in thread "main" java.lang.InstantiationException: Foo
              at java.base/jdk.internal.misc.Unsafe.allocateInstance(Native Method)
              at java.base/java.lang.invoke.DirectMethodHandle.allocateInstance(DirectMethodHandle.java:501)
              at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:336)
              at Test.ctorRef$main$0(test.groovy)
              at Test.main(test.groovy:10)
       

      Expected behavior

      The program should have been rejected instead.

      Attachments

        Activity

          People

            emilles Eric Milles
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: