-
Bug
-
Resolution: Fixed
-
P4
-
repo-valhalla
-
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.
(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.