1 /*
 2  * @test /nodynamiccopyright/
 3  * @bug 8267843
 4  * @summary Check that javac diagnoses `this` being passed around and instance method being invoked before value class instance is fully initialized.
 5  * @enablePreview
 6  * @compile/fail/ref=DualNonDuplicateErrors.out -XDrawDiagnostics DualNonDuplicateErrors.java
 7  */
 8 
 9 public value class DualNonDuplicateErrors {
10 
11     int x;
12 
13     DualNonDuplicateErrors() {
14         // The call below should trigger two errors - they are not duplicates really.
15         // First one is for `this` being passed around ("exposed")
16         // Second is for instance method being invoked thereby allowing that method to
17         // observe the value class instance in a partially initialized state.
18         foo(this);
19         x = 10;
20         super();
21         foo(this); // No error here.
22     }
23 
24     void foo(DualNonDuplicateErrors x) {
25     }
26 }