Sat, 22 Dec 2018 13:10:38 -0800
Added tag jdk8u202-b25 for changeset 15d8c732039b
1 /*
2 * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
24 /*
25 * @test
26 * @bug 4319507
27 * @summary Verify correct implementation of JLS2e 6.6.2.1
28 * @author maddox
29 *
30 * @run compile ProtectedMemberAccess1.java
31 */
33 import pkg.SuperClass;
35 class ProtectedMemberAccess1a extends SuperClass {
37 // Access to a protected member via its simple name
38 // is always legal in a subclass of the class in
39 // which the member is declared.
41 int i = pi;
42 int j = spi;
44 int x = pm();
45 int y = spm();
47 pC obj1;
48 spC obj2;
50 pI obj3;
51 spI obj4;
53 Object o1 = (pC) null;
54 Object o2 = (spC) null;
56 Object o3 = (pI) null;
57 Object o4 = (spI) null;
59 class C1 extends pC {}
60 class C2 extends spC {}
62 interface I1 extends pI {}
63 interface I2 extends spI {}
65 static {
67 spi = 2;
69 int y = spm();
71 pC obj1;
72 spC obj2;
74 pI obj3;
75 spI obj4;
77 Object o1 = (pC) null;
78 Object o2 = (spC) null;
80 Object o3 = (pI) null;
81 Object o4 = (spI) null;
83 //class C1 extends pC {}
84 class C2 extends spC {}
86 //interface I1 extends pI {}
87 //interface I2 extends spI {}
89 }
91 void m() {
93 pi = 1;
94 spi = 2;
96 int x = pm();
97 int y = spm();
99 pC obj1;
100 spC obj2;
102 pI obj3;
103 spI obj4;
105 Object o1 = (pC) null;
106 Object o2 = (spC) null;
108 Object o3 = (pI) null;
109 Object o4 = (spI) null;
111 class C1 extends pC {}
112 class C2 extends spC {}
114 //interface I1 extends pI {}
115 //interface I2 extends spI {}
117 }
119 class Inner {
121 int i = pi;
122 int j = spi;
124 int x = pm();
125 int y = spm();
127 pC obj1;
128 spC obj2;
130 pI obj3;
131 spI obj4;
133 Object o1 = (pC) null;
134 Object o2 = (spC) null;
136 Object o3 = (pI) null;
137 Object o4 = (spI) null;
139 class C1 extends pC {}
140 class C2 extends spC {}
142 //interface I1 extends pI {}
143 //interface I2 extends spI {}
145 // Not allowed in inner classes.
146 // static { ... }
148 void m() {
150 pi = 1;
151 spi = 2;
153 int x = pm();
154 int y = spm();
156 pC obj1;
157 spC obj2;
159 pI obj3;
160 spI obj4;
162 Object o1 = (pC) null;
163 Object o2 = (spC) null;
165 Object o3 = (pI) null;
166 Object o4 = (spI) null;
168 class C1 extends pC {}
169 class C2 extends spC {}
171 //interface I1 extends pI {}
172 //interface I2 extends spI {}
173 }
174 }
176 }
178 class ProtectedMemberAccess2a extends pkg.SuperClass {
180 // Access to a protected instance (non-static) field, instance method,
181 // or member type by a qualified name is always legal in a subclass of
182 // the class in which the member is declared. Such access to a protected
183 // instance field or instance method is allowed if the qualifying type
184 // or the type of the qualifying expression is (a subclass of) the class
185 // in which the reference occurs.
187 ProtectedMemberAccess2a x =
188 new ProtectedMemberAccess2a();
190 static ProtectedMemberAccess2a sx =
191 new ProtectedMemberAccess2a();
193 int i = x.pi;
194 int j = x.spi;
196 int n = sx.pi;
197 int m = sx.spi;
199 static int sn = sx.pi;
200 static int sm = sx.spi;
202 int w = x.pm();
203 int y = x.spm();
205 int u = sx.pm();
206 int v = sx.spm();
208 ProtectedMemberAccess2a.pC obj1;
209 ProtectedMemberAccess2a.spC obj2;
211 ProtectedMemberAccess2a.pI obj3;
212 ProtectedMemberAccess2a.spI obj4;
214 Object o1 = (ProtectedMemberAccess2a.pC) null;
215 Object o2 = (ProtectedMemberAccess2a.spC) null;
217 Object o3 = (ProtectedMemberAccess2a.pI) null;
218 Object o4 = (ProtectedMemberAccess2a.spI) null;
220 class C1 extends ProtectedMemberAccess2a.pC {}
221 class C2 extends ProtectedMemberAccess2a.spC {}
223 interface I1 extends ProtectedMemberAccess2a.pI {}
224 interface I2 extends ProtectedMemberAccess2a.spI {}
226 static {
228 ProtectedMemberAccess2a lx =
229 new ProtectedMemberAccess2a();
231 sx.pi = 1;
232 sx.spi = 2;
234 lx.pi = 1;
235 lx.spi = 2;
237 int n = sx.pi;
238 int m = sx.spi;
240 int k = lx.pi;
241 int l = lx.spi;
243 int u = sx.pm();
244 int v = sx.spm();
246 int w = lx.pm();
247 int z = lx.spm();
249 ProtectedMemberAccess2a.pC obj1;
250 ProtectedMemberAccess2a.spC obj2;
252 ProtectedMemberAccess2a.pI obj3;
253 ProtectedMemberAccess2a.spI obj4;
255 Object o1 = (ProtectedMemberAccess2a.pC) null;
256 Object o2 = (ProtectedMemberAccess2a.spC) null;
258 Object o3 = (ProtectedMemberAccess2a.pI) null;
259 Object o4 = (ProtectedMemberAccess2a.spI) null;
261 //class C1 extends ProtectedMemberAccess2a.pC {}
262 class C2 extends ProtectedMemberAccess2a.spC {}
264 //interface I1 extends ProtectedMemberAccess2a.pI {}
265 //interface I2 extends ProtectedMemberAccess2a.spI {}
267 }
269 void m() {
271 ProtectedMemberAccess2a lx =
272 new ProtectedMemberAccess2a();
274 x.pi = 1;
275 x.spi = 2;
277 sx.pi = 1;
278 sx.spi = 2;
280 lx.pi = 1;
281 lx.spi = 2;
283 int t = x.pm();
284 int y = x.spm();
286 int u = sx.pm();
287 int v = sx.spm();
289 int w = lx.pm();
290 int z = lx.spm();
292 int i = x.pi;
293 int j = x.spi;
295 int n = sx.pi;
296 int m = sx.spi;
298 int k = lx.pi;
299 int l = lx.spi;
301 ProtectedMemberAccess2a.pC obj1;
302 ProtectedMemberAccess2a.spC obj2;
304 ProtectedMemberAccess2a.pI obj3;
305 ProtectedMemberAccess2a.spI obj4;
307 Object o1 = (ProtectedMemberAccess2a.pC) null;
308 Object o2 = (ProtectedMemberAccess2a.spC) null;
310 Object o3 = (ProtectedMemberAccess2a.pI) null;
311 Object o4 = (ProtectedMemberAccess2a.spI) null;
313 class C1 extends ProtectedMemberAccess2a.pC {}
314 class C2 extends ProtectedMemberAccess2a.spC {}
316 //interface I1 extends ProtectedMemberAccess2a.pI {}
317 //interface I2 extends ProtectedMemberAccess2a.spI {}
319 }
321 class Inner {
323 int i = x.pi;
324 int j = x.spi;
326 int n = sx.pi;
327 int m = sx.spi;
329 //static int sn = sx.pi;
330 //static int sm = sx.spi;
332 int w = x.pm();
333 int y = x.spm();
335 int u = sx.pm();
336 int v = sx.spm();
338 ProtectedMemberAccess2a.pC obj1;
339 ProtectedMemberAccess2a.spC obj2;
341 ProtectedMemberAccess2a.pI obj3;
342 ProtectedMemberAccess2a.spI obj4;
344 Object o1 = (ProtectedMemberAccess2a.pC) null;
345 Object o2 = (ProtectedMemberAccess2a.spC) null;
347 Object o3 = (ProtectedMemberAccess2a.pI) null;
348 Object o4 = (ProtectedMemberAccess2a.spI) null;
350 class C1 extends ProtectedMemberAccess2a.pC {}
351 class C2 extends ProtectedMemberAccess2a.spC {}
353 //interface I1 extends ProtectedMemberAccess2a.pI {}
354 //interface I2 extends ProtectedMemberAccess2a.spI {}
356 // Not allowed in inner classes.
357 // static { ... }
359 void m() {
361 ProtectedMemberAccess2a lx =
362 new ProtectedMemberAccess2a();
364 x.pi = 1;
365 x.spi = 2;
367 sx.pi = 1;
368 sx.spi = 2;
370 lx.pi = 1;
371 lx.spi = 2;
373 int t = x.pm();
374 int y = x.spm();
376 int u = sx.pm();
377 int v = sx.spm();
379 int w = lx.pm();
380 int z = lx.spm();
382 int i = x.pi;
383 int j = x.spi;
385 int n = sx.pi;
386 int m = sx.spi;
388 int k = lx.pi;
389 int l = lx.spi;
391 ProtectedMemberAccess2a.pC obj1;
392 ProtectedMemberAccess2a.spC obj2;
394 ProtectedMemberAccess2a.pI obj3;
395 ProtectedMemberAccess2a.spI obj4;
397 Object o1 = (ProtectedMemberAccess2a.pC) null;
398 Object o2 = (ProtectedMemberAccess2a.spC) null;
400 Object o3 = (ProtectedMemberAccess2a.pI) null;
401 Object o4 = (ProtectedMemberAccess2a.spI) null;
403 class C1 extends ProtectedMemberAccess2a.pC {}
404 class C2 extends ProtectedMemberAccess2a.spC {}
406 //interface I1 extends ProtectedMemberAccess2a.pI {}
407 //interface I2 extends ProtectedMemberAccess2a.spI {}
409 }
411 }
413 }
416 class SubClass extends ProtectedMemberAccess3a { }
418 class ProtectedMemberAccess3a extends pkg.SuperClass {
420 // Access to a protected instance (non-static) field, instance method,
421 // or member type by a qualified name is always legal in a subclass of
422 // the class in which the member is declared. Such access to a protected
423 // instance field or instance method is allowed if the qualifying type
424 // or the type of the qualifying expression is (a subclass of) the class
425 // in which the reference occurs.
427 SubClass x = new SubClass();
429 static SubClass sx = new SubClass();
431 int i = x.pi;
432 int j = x.spi;
434 int n = sx.pi;
435 int m = sx.spi;
437 static int sn = sx.pi;
438 static int sm = sx.spi;
440 int w = x.pm();
441 int y = x.spm();
443 int u = sx.pm();
444 int v = sx.spm();
446 SubClass.pC obj1;
447 SubClass.spC obj2;
449 SubClass.pI obj3;
450 SubClass.spI obj4;
452 Object o1 = (SubClass.pC) null;
453 Object o2 = (SubClass.spC) null;
455 Object o3 = (SubClass.pI) null;
456 Object o4 = (SubClass.spI) null;
458 class C1 extends SubClass.pC {}
459 class C2 extends SubClass.spC {}
461 interface I1 extends SubClass.pI {}
462 interface I2 extends SubClass.spI {}
464 static {
466 SubClass lx = new SubClass();
468 sx.pi = 1;
469 sx.spi = 2;
471 lx.pi = 1;
472 lx.spi = 2;
474 int n = sx.pi;
475 int m = sx.spi;
477 int k = lx.pi;
478 int l = lx.spi;
480 int u = sx.pm();
481 int v = sx.spm();
483 int w = lx.pm();
484 int z = lx.spm();
486 SubClass.pC obj1;
487 SubClass.spC obj2;
489 SubClass.pI obj3;
490 SubClass.spI obj4;
492 Object o1 = (SubClass.pC) null;
493 Object o2 = (SubClass.spC) null;
495 Object o3 = (SubClass.pI) null;
496 Object o4 = (SubClass.spI) null;
498 //class C1 extends SubClass.pC {}
499 class C2 extends SubClass.spC {}
501 //interface I1 extends SubClass.pI {}
502 //interface I2 extends SubClass.spI {}
504 }
506 void m() {
508 SubClass lx = new SubClass();
510 x.pi = 1;
511 x.spi = 2;
513 sx.pi = 1;
514 sx.spi = 2;
516 lx.pi = 1;
517 lx.spi = 2;
519 int t = x.pm();
520 int y = x.spm();
522 int u = sx.pm();
523 int v = sx.spm();
525 int w = lx.pm();
526 int z = lx.spm();
528 int i = x.pi;
529 int j = x.spi;
531 int n = sx.pi;
532 int m = sx.spi;
534 int k = lx.pi;
535 int l = lx.spi;
537 SubClass.pC obj1;
538 SubClass.spC obj2;
540 SubClass.pI obj3;
541 SubClass.spI obj4;
543 Object o1 = (SubClass.pC) null;
544 Object o2 = (SubClass.spC) null;
546 Object o3 = (SubClass.pI) null;
547 Object o4 = (SubClass.spI) null;
549 class C1 extends SubClass.pC {}
550 class C2 extends SubClass.spC {}
552 //interface I1 extends SubClass.pI {}
553 //interface I2 extends SubClass.spI {}
555 }
557 class Inner {
559 int i = x.pi;
560 int j = x.spi;
562 int n = sx.pi;
563 int m = sx.spi;
565 //static int sn = sx.pi;
566 //static int sm = sx.spi;
568 int w = x.pm();
569 int y = x.spm();
571 int u = sx.pm();
572 int v = sx.spm();
574 SubClass.pC obj1;
575 SubClass.spC obj2;
577 SubClass.pI obj3;
578 SubClass.spI obj4;
580 Object o1 = (SubClass.pC) null;
581 Object o2 = (SubClass.spC) null;
583 Object o3 = (SubClass.pI) null;
584 Object o4 = (SubClass.spI) null;
586 class C1 extends SubClass.pC {}
587 class C2 extends SubClass.spC {}
589 //interface I1 extends SubClass.pI {}
590 //interface I2 extends SubClass.spI {}
592 // Not allowed in inner classes.
593 // static { ... }
595 void m() {
597 SubClass lx = new SubClass();
599 x.pi = 1;
600 x.spi = 2;
602 sx.pi = 1;
603 sx.spi = 2;
605 lx.pi = 1;
606 lx.spi = 2;
608 int t = x.pm();
609 int y = x.spm();
611 int u = sx.pm();
612 int v = sx.spm();
614 int w = lx.pm();
615 int z = lx.spm();
617 int i = x.pi;
618 int j = x.spi;
620 int n = sx.pi;
621 int m = sx.spi;
623 int k = lx.pi;
624 int l = lx.spi;
626 SubClass.pC obj1;
627 SubClass.spC obj2;
629 SubClass.pI obj3;
630 SubClass.spI obj4;
632 Object o1 = (SubClass.pC) null;
633 Object o2 = (SubClass.spC) null;
635 Object o3 = (SubClass.pI) null;
636 Object o4 = (SubClass.spI) null;
638 class C1 extends SubClass.pC {}
639 class C2 extends SubClass.spC {}
641 //interface I1 extends SubClass.pI {}
642 //interface I2 extends SubClass.spI {}
644 }
646 }
648 }