Better error message instead of "record header expected"?

Jaikiran Pai jai.forums2013 at gmail.com
Mon Sep 19 13:44:59 UTC 2022


Please consider this trivial code:

public record Record {

}

Trying to compile this results in:

javac Record.java

Record.java:1: error: record header expected

public record Record {
           ^

1 error

It isn't too clear what that error message means. It took me a while to 
realize that I had missed using the () after the record's name. Changing 
the source to:

public record Record() {

}

is what the error was trying to convey. Could this error message be 
improved?

By the way, notice that the error message was pointing to the "r" letter 
of the "record" keyword with the ^ sign. Is that right place for this 
error or should it have been after the "d" of the "Record" name, similar 
to what appears to be reported for constructors of classes, for example:

public class Event {
     public Event {

     }
}

javac Event.java

Event.java:2: error: <identifier> expected
     public Event {
                       ^
1 error

(not sure if mail clients will preserve the spacing - that ^ appears 
between the "t" and the "{")

-Jaikiran



More information about the compiler-dev mailing list