< prev index next >

test/langtools/tools/javac/SuperInit/SuperInitFails.java

Print this page
@@ -1,10 +1,11 @@
  /*
   * @test /nodynamiccopyright/
   * @bug 8194743
   * @summary Permit additional statements before this/super in constructors
   * @compile/fail/ref=SuperInitFails.out -XDrawDiagnostics SuperInitFails.java
+  * @enablePreview
   */
  import java.util.concurrent.atomic.AtomicReference;
  public class SuperInitFails extends AtomicReference<Object> implements Iterable<Object> {
  
      private int x;

@@ -149,11 +150,11 @@
              super();                    // this should FAIL
          };
      }
  
      public SuperInitFails(int[][] z) {
-         super((Runnable)() -> x);       // this should FAIL
+         super((Runnable)() -> System.err.println(x));       // this should FAIL
      }
  
      public SuperInitFails(long[][] z) {
          super(new Inner1());            // this should FAIL
      }

@@ -184,10 +185,21 @@
      public SuperInitFails(double[][] x) {
          Runnable r = () -> this.x = 7;  // this should FAIL
          super();
      }
  
+     public int xx;
+ 
+     SuperInitFails(short[][] ignore) {
+         int i = new SuperInitFails(){
+             void foo() {
+                 System.err.println(xx);  // this should fail
+             }
+         }.xx;  // this one is OK though
+         super(null);
+     }
+ 
      public static class Inner4 {
          Inner4() {
              Runnable r = () -> {
                  class A {
                      A() {

@@ -206,6 +218,29 @@
                  }
              };
              super();
          };
      }
+ 
+     static class Inner5 {
+         int x = 4;
+         static String m1(Runnable r) { return null; }
+         static String m2(Object r) { return null; }
+         Inner5() {
+             m1(() -> System.out.println(x)).toString();
+             m2(x).toString();
+             super();
+         }
+     }
+ 
+     static class Inner6 {
+         Inner6() {
+             class Bar {
+                 Bar() {
+                     Object o = Bar.this;
+                     super();
+                 }
+             }
+             super();
+         }
+     }
  }
< prev index next >