Thodoris Sotiropoulos created GROOVY-11385:
----------------------------------------------

             Summary: reference to the constructor of an abstract class is not 
detected
                 Key: GROOVY-11385
                 URL: https://issues.apache.org/jira/browse/GROOVY-11385
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
    Affects Versions: 5.0.0-alpha-8
            Reporter: Thodoris Sotiropoulos


I have the following program
{code:java}
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");
  }
} {code}
h3. Actual behavior

The program compiles but I get the following runtime exception, because I call 
the constructor of an abstract class.
{code:java}
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)
 {code}
h3. Expected behavior

The program should have been rejected instead.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to