You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Thodoris Sotiropoulos (Jira)" <ji...@apache.org> on 2021/03/01 15:14:00 UTC

[jira] [Created] (GROOVY-9960) STC fails to report missing constructor

Thodoris Sotiropoulos created GROOVY-9960:
---------------------------------------------

             Summary: STC fails to report missing constructor
                 Key: GROOVY-9960
                 URL: https://issues.apache.org/jira/browse/GROOVY-9960
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
    Affects Versions: 3.0.7
            Reporter: Thodoris Sotiropoulos


I have the following (incorrect) program
{code:java}
class A {
  String x;
  public A(String x) {
    this.x = x;
  }
}

class B extends A {}

public class Main {
  public static void main(String[] args) {
    B x = new B();
  }
}
{code}
h3. Actual Behaviour

The program compiles and when I run it I get the following RuntimeException, because we are missingĀ  constructor for class `A` that takes no parameters.
{code:java}
Exception in thread "main" java.lang.NoSuchMethodError: A: method 'void <init>()' not found
        at B.<init>(test.groovy)
        at Main.main(test.groovy:13)
{code}
h3. Expected Behaviour

The program should not compile and should report an error message. Note that javac reports something to the following
{code:java}
Main.java:8: error: constructor A in class A cannot be applied to given types;
class B extends A {}
^
  required: String
  found: no arguments
  reason: actual and formal argument lists differ in length
{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)