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

improve errors for record declarations

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 20
    • 18, 19, 20
    • tools
    • b23

      as reported in compiler-dev:

      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 "{")

      see: https://mail.openjdk.org/pipermail/compiler-dev/2022-September/020420.html

            vromero Vicente Arturo Romero Zaldivar
            vromero Vicente Arturo Romero Zaldivar
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: