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

[lworld] Double diagnostics when primitive class instance is passed around before being fully initialized

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • repo-valhalla
    • repo-valhalla
    • tools
    • generic
    • generic

      JEP 401 says:

      (Possibly) The constructor cannot make use of this except to set the fields in the constructor body, or perhaps after all fields are definitely assigned.

      // --

      The code that implements this seems to have a bug wherein duplicate errors are emitted. Consider:

      public primitive class X implements Cloneable {
          int x;
          int y;
          X() {
              foo(this);
          }
          void foo(X x) {
          }
      }

      Compiling this results in:

      X.java:5: error: primitive class instance should not be passed around before being fully initialized
              foo(this);
                  ^
      X.java:5: error: primitive class instance should not be passed around before being fully initialized
              foo(this);
                 ^
      X.java:6: error: variable x might not have been initialized
          }

      The first two errors are duplicates of each other. They seem to differ in DiagnosticPosition by 1 so both show up. But the concerned AST node is the same - it is to be examined why two messages appear.

            sadayapalam Srikanth Adayapalam (Inactive)
            sadayapalam Srikanth Adayapalam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: