1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
/*
* @test /nodynamiccopyright/
* @bug 8194743
* @summary Permit additional statements before this/super in constructors
* @compile/fail/ref=SuperInitFails.out -XDrawDiagnostics SuperInitFails.java
*/
import java.util.concurrent.atomic.AtomicReference;
public class SuperInitFails extends AtomicReference<Object> implements Iterable<Object> {
private int x;
/// GOOD EXAMPLES
public SuperInitFails() { // this should be OK
}
public SuperInitFails(Object x) {
this.x = x.hashCode(); // this should be OK
}
public SuperInitFails(byte x) {
super(); // this should be OK
}
public SuperInitFails(char x) {
this((int)x); // this should be OK
}
/// FAIL EXAMPLES
{
this(1); // this should FAIL
}
{
super(); // this should FAIL
}
void normalMethod1() {
super(); // this should FAIL
}
void normalMethod2() {
this(); // this should FAIL
}
void normalMethod3() {
Runnable r = () -> super(); // this should FAIL
}
void normalMethod4() {
Runnable r = () -> this(); // this should FAIL
}
public SuperInitFails(short x) {
hashCode(); // this should FAIL
super();
}
public SuperInitFails(float x) {
this.hashCode(); // this should FAIL
super();
}
public SuperInitFails(int x) {
super.hashCode(); // this should FAIL
super();
}
public SuperInitFails(long x) {
SuperInitFails.this.hashCode(); // this should FAIL
super();
}
public SuperInitFails(double x) {
SuperInitFails.super.hashCode(); // this should FAIL
super();
}
public SuperInitFails(byte[] x) {
{
super(); // this should FAIL
}
}
public SuperInitFails(char[] x) {
if (x.length == 0)
return; // this should FAIL
super();
}
public SuperInitFails(short[] x) {
this.x++; // this should FAIL
super();
}
public SuperInitFails(float[] x) {
System.identityHashCode(this); // this should FAIL
super();
}
public SuperInitFails(int[] x) {
this(this); // this should FAIL
}
public SuperInitFails(long[] x) {
this(Object.this); // this should FAIL
}
public SuperInitFails(double[] x) {
Iterable.super.spliterator(); // this should FAIL
super();
}
public SuperInitFails(byte[][] x) {
super(new Object() {
{
super(); // this should FAIL
}
});
}
public SuperInitFails(char[][] x) {
new Inner1(); // this should FAIL
super();
}
class Inner1 {
}
record Record1(int value) {
Record1(float x) { // this should FAIL
}
}
record Record2(int value) {
Record2(float x) { // this should FAIL
super();
}
}
@Override
public java.util.Iterator<Object> iterator() {
return null;
}
public SuperInitFails(float[][] x) {
Runnable r = () -> {
super(); // this should FAIL
};
}
public SuperInitFails(int[][] z) {
super((Runnable)() -> x); // this should FAIL
}
public SuperInitFails(long[][] z) {
super(new Inner1()); // this should FAIL
}
public static class Inner2 {
int x;
}
public static class Inner3 extends Inner2 {
int y;
Inner3(byte z) {
x = z; // this should FAIL
super();
}
Inner3(short z) {
this.x = z; // this should FAIL
super();
}
Inner3(char z) {
Inner3.this.x = z; // this should FAIL
super();
}
Inner3(int z) {
super.x = z; // this should FAIL
super();
}
}
public SuperInitFails(double[][] x) {
Runnable r = () -> this.x = 7; // this should FAIL
super();
}
public static class Inner4 {
Inner4() {
Runnable r = () -> {
class A {
A() {
return; // this should FAIL
super();
}
A(int x) {
{
this(); // this should FAIL
}
}
A(char x) {
super();
this(); // this should FAIL
}
}
};
super();
};
}
}
|