Sat, 22 Dec 2018 13:10:38 -0800
Added tag jdk8u202-b25 for changeset 15d8c732039b
duke@1 | 1 | /* |
duke@1 | 2 | * @test /nodynamiccopyright/ |
duke@1 | 3 | * @bug 4319507 4785453 |
duke@1 | 4 | * @summary Verify correct implementation of JLS2e 6.6.2.1 |
duke@1 | 5 | * @author maddox |
duke@1 | 6 | * |
jjg@611 | 7 | * @compile/fail/ref=ProtectedMemberAccess4.out -XDdiags=-simpleNames -XDdiagsFormat=%b:%l:%_%m ProtectedMemberAccess4.java |
duke@1 | 8 | */ |
duke@1 | 9 | |
duke@1 | 10 | // 33 errors expected. |
duke@1 | 11 | |
duke@1 | 12 | import pkg.SuperClass; |
duke@1 | 13 | |
duke@1 | 14 | class ProtectedMemberAccess4 extends pkg.SuperClass { |
duke@1 | 15 | |
duke@1 | 16 | // Access to a protected instance (non-static) field, instance method, |
duke@1 | 17 | // or member type by a qualified name is always legal in a subclass of |
duke@1 | 18 | // the class in which the member is declared. Such access to a protected |
duke@1 | 19 | // instance field or instance method is allowed only if the qualifying type |
duke@1 | 20 | // or the type of the qualifying expression is (a subclass of) the class |
duke@1 | 21 | // in which the reference occurs. In this test case, the qualifying type |
duke@1 | 22 | // is a superclass, thus all of the qualified references to instance fields |
duke@1 | 23 | // and instance methods are illegal. |
duke@1 | 24 | |
duke@1 | 25 | pkg.SuperClass x = new pkg.SuperClass(); |
duke@1 | 26 | |
duke@1 | 27 | static pkg.SuperClass sx = new pkg.SuperClass(); |
duke@1 | 28 | |
duke@1 | 29 | int i = x.pi; // illegal |
duke@1 | 30 | int j = x.spi; // ok |
duke@1 | 31 | |
duke@1 | 32 | int n = sx.pi; // illegal |
duke@1 | 33 | int m = sx.spi; // ok |
duke@1 | 34 | |
duke@1 | 35 | static int sn = sx.pi; // illegal |
duke@1 | 36 | static int sm = sx.spi; // ok |
duke@1 | 37 | |
duke@1 | 38 | int w = x.pm(); // illegal |
duke@1 | 39 | int y = x.spm(); // ok |
duke@1 | 40 | |
duke@1 | 41 | int u = sx.pm(); // illegal |
duke@1 | 42 | int v = sx.spm(); // ok |
duke@1 | 43 | |
duke@1 | 44 | pkg.SuperClass.pC obj1; // ok |
duke@1 | 45 | pkg.SuperClass.spC obj2; // ok |
duke@1 | 46 | |
duke@1 | 47 | pkg.SuperClass.pI obj3; // ok |
duke@1 | 48 | pkg.SuperClass.spI obj4; // ok |
duke@1 | 49 | |
duke@1 | 50 | Object o1 = (pkg.SuperClass.pC) null; // ok |
duke@1 | 51 | Object o2 = (pkg.SuperClass.spC) null; // ok |
duke@1 | 52 | |
duke@1 | 53 | Object o3 = (pkg.SuperClass.pI) null; // ok |
duke@1 | 54 | Object o4 = (pkg.SuperClass.spI) null; // ok |
duke@1 | 55 | |
duke@1 | 56 | class C1 extends pkg.SuperClass.pC {} // ok |
duke@1 | 57 | class C2 extends pkg.SuperClass.spC {} // ok |
duke@1 | 58 | |
duke@1 | 59 | interface I1 extends pkg.SuperClass.pI {} // ok |
duke@1 | 60 | interface I2 extends pkg.SuperClass.spI {} // ok |
duke@1 | 61 | |
duke@1 | 62 | static { |
duke@1 | 63 | |
duke@1 | 64 | pkg.SuperClass lx = new pkg.SuperClass(); |
duke@1 | 65 | |
duke@1 | 66 | sx.pi = 1; // illegal |
duke@1 | 67 | sx.spi = 2; // ok |
duke@1 | 68 | |
duke@1 | 69 | lx.pi = 1; // illegal |
duke@1 | 70 | lx.spi = 2; // ok |
duke@1 | 71 | |
duke@1 | 72 | int n = sx.pi; // illegal |
duke@1 | 73 | int m = sx.spi; // ok |
duke@1 | 74 | |
duke@1 | 75 | int k = lx.pi; // illegal |
duke@1 | 76 | int l = lx.spi; // ok |
duke@1 | 77 | |
duke@1 | 78 | int u = sx.pm(); // illegal |
duke@1 | 79 | int v = sx.spm(); // ok |
duke@1 | 80 | |
duke@1 | 81 | int w = lx.pm(); // illegal |
duke@1 | 82 | int z = lx.spm(); // ok |
duke@1 | 83 | |
duke@1 | 84 | pkg.SuperClass.pC obj1; // ok |
duke@1 | 85 | pkg.SuperClass.spC obj2; // ok |
duke@1 | 86 | |
duke@1 | 87 | pkg.SuperClass.pI obj3; // ok |
duke@1 | 88 | pkg.SuperClass.spI obj4; // ok |
duke@1 | 89 | |
duke@1 | 90 | Object o1 = (pkg.SuperClass.pC) null; // ok |
duke@1 | 91 | Object o2 = (pkg.SuperClass.spC) null; // ok |
duke@1 | 92 | |
duke@1 | 93 | Object o3 = (pkg.SuperClass.pI) null; // ok |
duke@1 | 94 | Object o4 = (pkg.SuperClass.spI) null; // ok |
duke@1 | 95 | |
duke@1 | 96 | //class C1 extends pkg.SuperClass.pC {} |
duke@1 | 97 | class C2 extends pkg.SuperClass.spC {} // ok |
duke@1 | 98 | |
duke@1 | 99 | //interface I1 extends pkg.SuperClass.pI {} |
duke@1 | 100 | //interface I2 extends pkg.SuperClass.spI {} |
duke@1 | 101 | |
duke@1 | 102 | } |
duke@1 | 103 | |
duke@1 | 104 | void m() { |
duke@1 | 105 | |
duke@1 | 106 | pkg.SuperClass lx = new pkg.SuperClass(); |
duke@1 | 107 | |
duke@1 | 108 | x.pi = 1; // illegal |
duke@1 | 109 | x.spi = 2; // ok |
duke@1 | 110 | |
duke@1 | 111 | sx.pi = 1; // illegal |
duke@1 | 112 | sx.spi = 2; // ok |
duke@1 | 113 | |
duke@1 | 114 | lx.pi = 1; // illegal |
duke@1 | 115 | lx.spi = 2; // ok |
duke@1 | 116 | |
duke@1 | 117 | int t = x.pm(); // illegal |
duke@1 | 118 | int y = x.spm(); // ok |
duke@1 | 119 | |
duke@1 | 120 | int u = sx.pm(); // illegal |
duke@1 | 121 | int v = sx.spm(); // ok |
duke@1 | 122 | |
duke@1 | 123 | int w = lx.pm(); // illegal |
duke@1 | 124 | int z = lx.spm(); // ok |
duke@1 | 125 | |
duke@1 | 126 | int i = x.pi; // illegal |
duke@1 | 127 | int j = x.spi; // ok |
duke@1 | 128 | |
duke@1 | 129 | int n = sx.pi; // illegal |
duke@1 | 130 | int m = sx.spi; // ok |
duke@1 | 131 | |
duke@1 | 132 | int k = lx.pi; // illegal |
duke@1 | 133 | int l = lx.spi; // ok |
duke@1 | 134 | |
duke@1 | 135 | pkg.SuperClass.pC obj1; // ok |
duke@1 | 136 | pkg.SuperClass.spC obj2; // ok |
duke@1 | 137 | |
duke@1 | 138 | pkg.SuperClass.pI obj3; // ok |
duke@1 | 139 | pkg.SuperClass.spI obj4; // ok |
duke@1 | 140 | |
duke@1 | 141 | Object o1 = (pkg.SuperClass.pC) null; // ok |
duke@1 | 142 | Object o2 = (pkg.SuperClass.spC) null; // ok |
duke@1 | 143 | |
duke@1 | 144 | Object o3 = (pkg.SuperClass.pI) null; // ok |
duke@1 | 145 | Object o4 = (pkg.SuperClass.spI) null; // ok |
duke@1 | 146 | |
duke@1 | 147 | class C1 extends pkg.SuperClass.pC {} // ok |
duke@1 | 148 | class C2 extends pkg.SuperClass.spC {} // ok |
duke@1 | 149 | |
duke@1 | 150 | //interface I1 extends pkg.SuperClass.pI {} |
duke@1 | 151 | //interface I2 extends pkg.SuperClass.spI {} |
duke@1 | 152 | |
duke@1 | 153 | } |
duke@1 | 154 | |
duke@1 | 155 | class Inner { |
duke@1 | 156 | |
duke@1 | 157 | int i = x.pi; // illegal |
duke@1 | 158 | int j = x.spi; // ok |
duke@1 | 159 | |
duke@1 | 160 | int n = sx.pi; // illegal |
duke@1 | 161 | int m = sx.spi; // ok |
duke@1 | 162 | |
duke@1 | 163 | //static int sn = sx.pi; |
duke@1 | 164 | //static int sm = sx.spi; |
duke@1 | 165 | |
duke@1 | 166 | int w = x.pm(); // illegal |
duke@1 | 167 | int y = x.spm(); // ok |
duke@1 | 168 | |
duke@1 | 169 | int u = sx.pm(); // illegal |
duke@1 | 170 | int v = sx.spm(); // ok |
duke@1 | 171 | |
duke@1 | 172 | pkg.SuperClass.pC obj1; // ok |
duke@1 | 173 | pkg.SuperClass.spC obj2; // ok |
duke@1 | 174 | |
duke@1 | 175 | pkg.SuperClass.pI obj3; // ok |
duke@1 | 176 | pkg.SuperClass.spI obj4; // ok |
duke@1 | 177 | |
duke@1 | 178 | Object o1 = (pkg.SuperClass.pC) null; // ok |
duke@1 | 179 | Object o2 = (pkg.SuperClass.spC) null; // ok |
duke@1 | 180 | |
duke@1 | 181 | Object o3 = (pkg.SuperClass.pI) null; // ok |
duke@1 | 182 | Object o4 = (pkg.SuperClass.spI) null; // ok |
duke@1 | 183 | |
duke@1 | 184 | class C1 extends pkg.SuperClass.pC {} // ok |
duke@1 | 185 | class C2 extends pkg.SuperClass.spC {} // ok |
duke@1 | 186 | |
duke@1 | 187 | //interface I1 extends pkg.SuperClass.pI {} |
duke@1 | 188 | //interface I2 extends pkg.SuperClass.spI {} |
duke@1 | 189 | |
duke@1 | 190 | // Not allowed in inner classes. |
duke@1 | 191 | // static { ... } |
duke@1 | 192 | |
duke@1 | 193 | void m() { |
duke@1 | 194 | |
duke@1 | 195 | pkg.SuperClass lx = new pkg.SuperClass(); |
duke@1 | 196 | |
duke@1 | 197 | x.pi = 1; // illegal |
duke@1 | 198 | x.spi = 2; // ok |
duke@1 | 199 | |
duke@1 | 200 | sx.pi = 1; // illegal |
duke@1 | 201 | sx.spi = 2; // ok |
duke@1 | 202 | |
duke@1 | 203 | lx.pi = 1; // illegal |
duke@1 | 204 | lx.spi = 2; // ok |
duke@1 | 205 | |
duke@1 | 206 | int t = x.pm(); // illegal |
duke@1 | 207 | int y = x.spm(); // ok |
duke@1 | 208 | |
duke@1 | 209 | int u = sx.pm(); // illegal |
duke@1 | 210 | int v = sx.spm(); // ok |
duke@1 | 211 | |
duke@1 | 212 | int w = lx.pm(); // illegal |
duke@1 | 213 | int z = lx.spm(); // ok |
duke@1 | 214 | |
duke@1 | 215 | int i = x.pi; // illegal |
duke@1 | 216 | int j = x.spi; // ok |
duke@1 | 217 | |
duke@1 | 218 | int n = sx.pi; // illegal |
duke@1 | 219 | int m = sx.spi; // ok |
duke@1 | 220 | |
duke@1 | 221 | int k = lx.pi; // illegal |
duke@1 | 222 | int l = lx.spi; // ok |
duke@1 | 223 | |
duke@1 | 224 | pkg.SuperClass.pC obj1; // ok |
duke@1 | 225 | pkg.SuperClass.spC obj2; // ok |
duke@1 | 226 | |
duke@1 | 227 | pkg.SuperClass.pI obj3; // ok |
duke@1 | 228 | pkg.SuperClass.spI obj4; // ok |
duke@1 | 229 | |
duke@1 | 230 | Object o1 = (pkg.SuperClass.pC) null; // ok |
duke@1 | 231 | Object o2 = (pkg.SuperClass.spC) null; // ok |
duke@1 | 232 | |
duke@1 | 233 | Object o3 = (pkg.SuperClass.pI) null; // ok |
duke@1 | 234 | Object o4 = (pkg.SuperClass.spI) null; // ok |
duke@1 | 235 | |
duke@1 | 236 | class C1 extends pkg.SuperClass.pC {} // ok |
duke@1 | 237 | class C2 extends pkg.SuperClass.spC {} // ok |
duke@1 | 238 | |
duke@1 | 239 | //interface I1 extends pkg.SuperClass.pI {} |
duke@1 | 240 | //interface I2 extends pkg.SuperClass.spI {} |
duke@1 | 241 | |
duke@1 | 242 | } |
duke@1 | 243 | |
duke@1 | 244 | } |
duke@1 | 245 | |
duke@1 | 246 | } |