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

Unclear error message: constructor is not canonical

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • None
    • tools
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 22.04.2 LTS
      openjdk version "20-internal" 2023-03-21
      OpenJDK Runtime Environment (build 20-internal-adhoc.admin1.jdk-jdk-20-34)
      OpenJDK 64-Bit Server VM (build 20-internal-adhoc.admin1.jdk-jdk-20-34, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      The error message that occurs when the default constructor of a record needs to be called is a bit unclear, especially since many developers don't know what a canonical constructor is. The error message just states: constructor is not canonical, so its first statement must invoke another constructor of class...
      It would be good to improve the error message, for example, by mentioning that just this(...) should be added to the first line of the constructor. Here is example code that illustrates how the error message is produced.

      public record Record1(int a){
      public Record1(int a, int b){}
      }


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: