Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/PrivateMethodsTest.java
41159 views
1
/*
2
* Copyright (c) 2013, 2021, 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
*/
23
24
/*
25
* @test
26
*
27
* @modules java.base/jdk.internal.org.objectweb.asm:+open java.base/jdk.internal.org.objectweb.asm.util:+open
28
* @library /vmTestbase /test/lib
29
*
30
* @comment build retransform.jar in current dir
31
* @run driver vm.runtime.defmeth.shared.BuildJar
32
*
33
* @run driver jdk.test.lib.FileInstaller . .
34
* @run main/othervm/native
35
* -agentlib:redefineClasses
36
* -javaagent:retransform.jar
37
* vm.runtime.defmeth.PrivateMethodsTest
38
*/
39
package vm.runtime.defmeth;
40
41
import java.util.Set;
42
43
import vm.runtime.defmeth.shared.DefMethTest;
44
import vm.runtime.defmeth.shared.annotation.NotApplicableFor;
45
import vm.runtime.defmeth.shared.builder.TestBuilder;
46
import vm.runtime.defmeth.shared.data.*;
47
48
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SYNCHRONIZED;
49
import static vm.runtime.defmeth.shared.data.method.body.CallMethod.Invoke.*;
50
import static vm.runtime.defmeth.shared.data.method.body.CallMethod.IndexbyteOp.*;
51
import static vm.runtime.defmeth.shared.ExecutionMode.*;
52
53
/**
54
* Scenarios on private methods in interfaces.
55
*/
56
public class PrivateMethodsTest extends DefMethTest {
57
58
public static void main(String[] args) {
59
DefMethTest.runTest(PrivateMethodsTest.class,
60
/* majorVer */ Set.of(MIN_MAJOR_VER, MAX_MAJOR_VER),
61
/* flags */ Set.of(0, ACC_SYNCHRONIZED),
62
/* redefine */ Set.of(false, true),
63
/* execMode */ Set.of(DIRECT, REFLECTION, INVOKE_EXACT, INVOKE_GENERIC, INVOKE_WITH_ARGS, INDY));
64
}
65
66
// invokevirtual & invokeinterface from same/subintf
67
// Spec change July 2013 to not allow invokevirtual or invokeinterface
68
// to even see an interface private method
69
// Throw ICCE if method resolution returns interface private method
70
71
// Spec change JDK 11 - invokeinterface can be used for private interface
72
// methods and is now the preferred invocation bytecode - so no ICCE.
73
// Private methods are skipped during selection unless the resolved method
74
// is private.
75
// This change is not dependent on the classfile version.
76
77
// Note on reflection testing:
78
// Reflection is only used for the initial callsite, which is not always
79
// the method of interest. For example where a default method m() calls
80
// the private interface method privateM(). It is the latter call we are
81
// really testing, but it is the call of the default method that occurs
82
// via reflection.
83
84
/*
85
* testPrivateInvokeVirtual
86
*
87
* interface I {
88
* private int privateM() { return 1; }
89
* default public int m() { return (I)this.privateM(); } // invokevirtual
90
* }
91
* class C implements I {}
92
*
93
* TEST: I o = new C(); o.m()I throws VerifyError
94
* TEST: C o = new C(); o.m()I throws VerifyError
95
*/
96
@NotApplicableFor(modes = { REDEFINITION }) // Can't redefine a class that gets error during loading
97
public void testPrivateInvokeVirtual(TestBuilder b) {
98
Interface I = b.intf("I")
99
.defaultMethod("privateM", "()I")
100
.private_().returns(1).build()
101
102
// force an invokevirtual of an IMR to test verification code
103
.defaultMethod("m", "()I")
104
.invoke(VIRTUAL, b.intfByName("I"), null, "privateM", "()I", INTERFACEMETHODREF).build()
105
.build();
106
107
ConcreteClass C = b.clazz("C").implement(I).build();
108
109
b.test().callSite(I, C, "m", "()I").throws_(VerifyError.class).done()
110
.test().callSite(C, C, "m", "()I").throws_(VerifyError.class).done();
111
}
112
113
/*
114
* testPrivateInvokeIntf
115
*
116
* interface I {
117
* private int privateM() { return 1; }
118
* default public int m() { return (I)this.privateM(); } // invokeinterface
119
* }
120
* class C implements I {}
121
*
122
* TEST: I o = new C(); o.m()I returns 1
123
* TEST: C o = new C(); o.m()I returns 1
124
*/
125
public void testPrivateInvokeIntf(TestBuilder b) {
126
Interface I = b.intf("I")
127
.defaultMethod("privateM", "()I")
128
.private_().returns(1).build()
129
.defaultMethod("m", "()I")
130
.invoke(INTERFACE, b.intfByName("I"), null, "privateM", "()I", CALLSITE).build()
131
.build();
132
133
ConcreteClass C = b.clazz("C").implement(I).build();
134
135
b.test().callSite(I, C, "m", "()I").returns(1).done()
136
.test().callSite(C, C, "m", "()I").returns(1).done();
137
}
138
139
/*
140
* testPrivateInvokeStatic
141
*
142
* interface I {
143
* private int privateM() { return 1; }
144
* default public int m() { return I.privateM(); } // invokestatic
145
* }
146
* class C implements I {}
147
*
148
* TEST: I o = new C(); o.m()I throws IncompatibleClassChangeError
149
* TEST: C o = new C(); o.m()I throws IncompatibleClassChangeError
150
*/
151
public void testPrivateInvokeStatic(TestBuilder b) {
152
Interface I = b.intf("I")
153
.defaultMethod("privateM", "()I")
154
.private_().returns(1).build()
155
.defaultMethod("m", "()I")
156
.invoke(STATIC, b.intfByName("I"), null, "privateM", "()I", CALLSITE).build()
157
.build();
158
159
ConcreteClass C = b.clazz("C").implement(I).build();
160
161
b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done()
162
.test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
163
}
164
165
// call from another default method in the same interface
166
/*
167
* testPrivateCallSameClass
168
*
169
* interface I {
170
* private privateM()I { return 1; }
171
* default public int m() { return I.super.privateM(); } // invokespecial
172
* }
173
* class C implements I {}
174
*
175
* TEST: { I o = new C(); o.m()I == 1; }
176
* TEST: { C o = new C(); o.m()I == 1; }
177
*/
178
public void testPrivateCallSameClass(TestBuilder b) {
179
Interface I = b.intf("I")
180
.defaultMethod("privateM", "()I")
181
.private_().returns(1).build()
182
.defaultMethod("m", "()I")
183
.invokeSpecial(b.intfByName("I"), "privateM", "()I").build()
184
.build();
185
186
ConcreteClass C = b.clazz("C").implement(I).build();
187
188
b.test().callSite(I, C, "m", "()I").returns(1).done()
189
.test().callSite(C, C, "m", "()I").returns(1).done();
190
}
191
192
/*
193
* testPrivateCallSubIntf
194
*
195
* Attempt to call from subinterface fails
196
197
* interface I {
198
* private privateM()I { return 1; }
199
* }
200
* J, K, L use invokespecial
201
* interface J extends I {
202
* default public int m() { return I.super.privateM(); }
203
* }
204
* interface K extends I {
205
* default public int m() { return K.super.privateM(); }
206
* }
207
* interface L extends J {
208
* default public int m() { return I.super.privateM(); }
209
* }
210
* class C implements J {}
211
* class D implements K {}
212
* class E implements L {}
213
*
214
* TEST: { J o = new C(); o.m()I throws IAE; }
215
* TEST: { C o = new C(); o.m()I throws IAE; }
216
* TEST: { K o = new D(); o.m()I throws NSME; } // does not see
217
* TEST: { D o = new D(); o.m()I throws NSME; }
218
* TEST: { L o = new E(); o.m()I throws VerifyError; } // VerifyError intfmethodref
219
* TEST: { E o = new E(); o.m()I throws VerifyError; }
220
*/
221
@NotApplicableFor(modes = { REDEFINITION }) // Can't redefine a class that gets error during loading
222
public void testPrivateCallSubIntf(TestBuilder b) {
223
Interface I = b.intf("I")
224
.defaultMethod("privateM", "()I")
225
.private_().returns(1).build()
226
.build();
227
228
Interface J = b.intf("J").extend(I)
229
.defaultMethod("m", "()I")
230
.invokeSpecial(I, "privateM", "()I").build()
231
.build();
232
233
Interface K = b.intf("K").extend(J)
234
.defaultMethod("m", "()I")
235
.invokeSpecial(b.intfByName("K"), "privateM", "()I").build()
236
.build();
237
238
// L.privateM -> J -> L (I.privateM call)
239
Interface L = b.intf("L").extend(J)
240
.defaultMethod("m", "()I")
241
.invokeSpecial(I, "privateM", "()I").build()
242
.build();
243
244
ConcreteClass C = b.clazz("C").implement(J).build();
245
246
ConcreteClass D = b.clazz("D").implement(K).build();
247
248
ConcreteClass E = b.clazz("E").implement(L).build();
249
250
b.test().callSite(J, C, "m", "()I").throws_(IllegalAccessError.class).done()
251
.test().callSite(C, C, "m", "()I").throws_(IllegalAccessError.class).done()
252
253
.test().callSite(K, D, "m", "()I").throws_(NoSuchMethodError.class).done()
254
.test().callSite(D, D, "m", "()I").throws_(NoSuchMethodError.class).done()
255
256
.test().callSite(L, E, "m", "()I").throws_(VerifyError.class).done()
257
.test().callSite(E, E, "m", "()I").throws_(VerifyError.class).done();
258
}
259
260
/*
261
* Attempt to call from subclass fails
262
*
263
* interface I {
264
* private privateM()I { return 1; }
265
* }
266
* class C implements I {
267
* public int m() { return I.super.privateM(); }
268
* }
269
* class D extends C {
270
* public int m() { return I.super.privateM(); }
271
* }
272
* class E extends C {
273
* public int m() { return C.super.privateM(); }
274
* }
275
*
276
* TEST: { C o = new C(); o.m()I throws IllegalAccessError (or VerifyError) }
277
* TEST: { D o = new D(); o.m()I throws VerifyError }
278
* TEST: { E o = new E(); o.m()I throws NoSuchMethodError (or VerifyError); }
279
*/
280
@NotApplicableFor(modes = { REDEFINITION }) // Can't redefine a class that gets error during loading
281
public void testPrivateCallImplClass(TestBuilder b) {
282
Interface I = b.intf("I")
283
.defaultMethod("privateM", "()I")
284
.private_().returns(1).build()
285
.build();
286
287
ConcreteClass C = b.clazz("C").implement(I)
288
.concreteMethod("m", "()I")
289
.invokeSpecial(I, "privateM", "()I").build()
290
.build();
291
292
ConcreteClass D = b.clazz("D").extend(C)
293
.concreteMethod("m", "()I")
294
.invokeSpecial(I, "privateM", "()I").build()
295
.build();
296
297
ConcreteClass E = b.clazz("E").extend(C)
298
.concreteMethod("m", "()I")
299
.invokeSpecial(C, "privateM", "()I").build()
300
.build();
301
302
Class eeExpectedClass;
303
Class ccExpectedClass;
304
if (factory.getVer() >= 52) {
305
eeExpectedClass = NoSuchMethodError.class;
306
ccExpectedClass = IllegalAccessError.class;
307
} else {
308
// The test gets a VerifyError in this case due to an
309
// invokespecial IMR bytecode. This was not allowed
310
// until class file version 52. (See 8030249.)
311
eeExpectedClass = VerifyError.class;
312
ccExpectedClass = VerifyError.class;
313
}
314
b.test().callSite(C, C, "m", "()I").throws_(ccExpectedClass).done()
315
.test().callSite(D, D, "m", "()I").throws_(VerifyError.class).done()
316
.test().callSite(E, E, "m", "()I").throws_(eeExpectedClass).done();
317
}
318
319
// doesn't participate in default method analysis
320
// method overriding
321
322
/*
323
* testPrivate
324
*
325
* interface I {
326
* private int m() { return 1; }
327
* }
328
* class C implements I {}
329
*
330
* TEST: { I o = new C(); o.m()I throws IllegalAccessError; }
331
* TEST: { C o = new C(); o.m()I throws NoSuchMethodError; }
332
*/
333
public void testPrivate(TestBuilder b) {
334
Interface I = b.intf("I")
335
.defaultMethod("m", "()I")
336
.private_().returns(1).build()
337
.build();
338
339
ConcreteClass C = b.clazz("C").implement(I).build();
340
341
b.test().privateCallSite(I, C, "m", "()I").throws_(IllegalAccessError.class).done()
342
.test(). callSite(C, C, "m", "()I").throws_(NoSuchMethodError.class).done();
343
}
344
345
/*
346
* testPrivateVsConcrete
347
*
348
* interface I {
349
* private int m() { return 1; }
350
* }
351
* class C implements I {
352
* public int m() { return 2; }
353
* }
354
*
355
* TEST: { I o = new C(); o.m()I == IllegalAccessError; }
356
* TEST: { C o = new C(); o.m()I == 2; }
357
*/
358
public void testPrivateVsConcrete(TestBuilder b) {
359
Interface I = b.intf("I")
360
.defaultMethod("m", "()I")
361
.private_().returns(1).build()
362
.build();
363
364
ConcreteClass C = b.clazz("C").implement(I)
365
.concreteMethod("m", "()I").returns(2).build()
366
.build();
367
368
b.test().privateCallSite(I, C, "m", "()I").throws_(IllegalAccessError.class).done()
369
.test(). callSite(C, C, "m", "()I").returns(2).done();
370
}
371
372
/*
373
* testPublicOverridePrivate
374
*
375
* interface I {
376
* private int m() { return 1; }
377
* }
378
* interface J extends I {
379
* default public int m() { return 2; }
380
* }
381
* class C implements J {}
382
*
383
* TEST: { I o = new C(); o.m()I throws IllegalAccessError; }
384
* TEST: { J o = new C(); o.m()I == 2; }
385
* TEST: { C o = new C(); o.m()I == 2; }
386
*/
387
public void testPublicOverridePrivate(TestBuilder b) {
388
Interface I = b.intf("I")
389
.defaultMethod("m", "()I")
390
.private_().returns(1).build()
391
.build();
392
393
Interface J = b.intf("J").extend(I)
394
.defaultMethod("m", "()I")
395
.returns(2).build()
396
.build();
397
398
ConcreteClass C = b.clazz("C").implement(J).build();
399
400
b.test().privateCallSite(I, C, "m", "()I").throws_(IllegalAccessError.class).done()
401
.test(). callSite(J, C, "m", "()I").returns(2).done()
402
.test(). callSite(C, C, "m", "()I").returns(2).done();
403
}
404
405
/*
406
* testPrivateOverrideDefault
407
*
408
* interface I {
409
* default public int m() { return 1; }
410
* }
411
* interface J extends I {
412
* private int m() { return 2; }
413
* }
414
* class C implements J {}
415
*
416
* TEST: { I o = new C(); o.m()I == 1; }
417
* TEST: { J o = new C(); o.m()I == IllegalAccessError; } II J.m priv
418
* TEST: { C o = new C(); o.m()I == 1; }
419
*/
420
public void testPrivateOverrideDefault(TestBuilder b) {
421
Interface I = b.intf("I")
422
.defaultMethod("m", "()I")
423
.returns(1).build()
424
.build();
425
426
Interface J = b.intf("J").extend(I)
427
.defaultMethod("m", "()I")
428
.private_().returns(2).build()
429
.build();
430
431
ConcreteClass C = b.clazz("C").implement(J).build();
432
433
b.test().callSite(I, C, "m", "()I").returns(1).done()
434
.test().privateCallSite(J, C, "m", "()I").throws_(IllegalAccessError.class).done()
435
.test().callSite(C, C, "m", "()I").returns(1).done();
436
}
437
438
/*
439
* testPrivateReabstract
440
*
441
* interface I {
442
* private int m() { return 1; }
443
* }
444
* interface J extends I {
445
* abstract public int m();
446
* }
447
* class C implements J {}
448
*
449
* TEST: { I o = new C(); o.m()I throws IllegalAccessError; } II I.m
450
* TEST: { J o = new C(); o.m()I throws java/lang/AbstractMethodError; }
451
* TEST: { C o = new C(); o.m()I throws java/lang/AbstractMethodError; }
452
*/
453
public void testPrivateReabstract(TestBuilder b) {
454
Interface I = b.intf("I")
455
.defaultMethod("m", "()I")
456
.private_().returns(1).build()
457
.build();
458
459
Interface J = b.intf("J").extend(I)
460
.abstractMethod("m", "()I").build()
461
.build();
462
463
ConcreteClass C = b.clazz("C").implement(J).build();
464
465
b.test().privateCallSite(I, C, "m", "()I").throws_(IllegalAccessError.class).done()
466
.test(). callSite(J, C, "m", "()I").throws_(AbstractMethodError.class).done()
467
.test(). callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done();
468
}
469
470
/*
471
* testPrivateOverrideAbstract
472
*
473
* interface I {
474
* abstract public int m();
475
* }
476
* interface J extends I {
477
* private int m() { return 1; }
478
* }
479
* class C implements J {}
480
*
481
* TEST: { I o = new C(); o.m()I throws AbstractMethodError }
482
* TEST: { J o = new C(); o.m()I throws IllegalAccessError }
483
* TEST: { C o = new C(); o.m()I throws AbstractMethodError }
484
*/
485
public void testPrivateOverrideAbstract(TestBuilder b) {
486
Interface I = b.intf("I")
487
.abstractMethod("m", "()I").build()
488
.build();
489
490
Interface J = b.intf("J").extend(I)
491
.defaultMethod("m", "()I")
492
.private_().returns(1).build()
493
.build();
494
495
ConcreteClass C = b.clazz("C").implement(J).build();
496
497
b.test().callSite(I, C, "m", "()I").throws_(AbstractMethodError.class).done()
498
.test().privateCallSite(J, C, "m", "()I").throws_(IllegalAccessError.class).done()
499
.test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done();
500
}
501
502
/*
503
* testPrivateInherited
504
*
505
* interface I {
506
* private int m() { return 1; }
507
* }
508
* class B implements I {}
509
* class C extends B {}
510
*
511
* TEST: { I o = new C(); o.m()I throws IllegalAccessError } II I.m
512
* TEST: { B o = new C(); o.m()I throws NoSuchMethodError }
513
* TEST: { C o = new C(); o.m()I throws NoSuchMethodError }
514
*/
515
public void testPrivateInherited(TestBuilder b) {
516
Interface I = b.intf("I")
517
.defaultMethod("m", "()I")
518
.private_().returns(1).build()
519
.build();
520
521
ConcreteClass B = b.clazz("B").implement(I).build();
522
ConcreteClass C = b.clazz("C").extend(B).build();
523
524
b.test().privateCallSite(I, C, "m","()I").throws_(IllegalAccessError.class).done()
525
.test(). callSite(B, C, "m","()I").throws_(NoSuchMethodError.class).done()
526
.test(). callSite(C, C, "m","()I").throws_(NoSuchMethodError.class).done();
527
}
528
529
/*
530
* testPrivateVsConcreteInherited
531
*
532
* interface I {
533
* private int m() { return 1; }
534
* }
535
* class B {
536
* public int m() { return 2; }
537
* }
538
* class C extends B implements I {}
539
*
540
* TEST: { I o = new C(); o.m()I == throws IllegalAccessError; }
541
* TEST: { B o = new C(); o.m()I == 2; }
542
* TEST: { C o = new C(); o.m()I == 2; }
543
*/
544
public void testPrivateVsConcreteInherited(TestBuilder b) {
545
Interface I = b.intf("I")
546
.defaultMethod("m", "()I")
547
.private_().returns(1).build()
548
.build();
549
550
ConcreteClass B = b.clazz("B")
551
.concreteMethod("m", "()I").returns(2).build()
552
.build();
553
554
ConcreteClass C = b.clazz("C").extend(B).implement(I).build();
555
556
b.test().privateCallSite(I, C, "m","()I").throws_(IllegalAccessError.class).done()
557
.test(). callSite(B, C, "m","()I").returns(2).done()
558
.test(). callSite(C, C, "m","()I").returns(2).done();
559
}
560
561
/*
562
* testPrivateConflict
563
*
564
* Conflicting methods
565
*
566
* interface I {
567
* private int m() { return 1; }
568
* }
569
* interface J {
570
* default public int m() { return 2; }
571
* }
572
* class C implements I, J {}
573
*
574
* TEST: { I o = new C(); o.m()I throws IllegalAccessError; }
575
* TEST: { J o = new C(); o.m()I == 2; }
576
* TEST: { C o = new C(); o.m()I == 2; }
577
*/
578
public void testPrivateConflict(TestBuilder b) {
579
Interface I = b.intf("I")
580
.defaultMethod("m", "()I").private_().returns(1).build()
581
.build();
582
583
Interface J = b.intf("J")
584
.defaultMethod("m", "()I").returns(2).build()
585
.build();
586
587
ConcreteClass C = b.clazz("C").implement(I,J).build();
588
589
b.test().privateCallSite(I, C, "m", "()I").throws_(IllegalAccessError.class).done()
590
.test(). callSite(J, C, "m", "()I").returns(2).done()
591
.test(). callSite(C, C, "m", "()I").returns(2).done();
592
}
593
/*
594
* testPrivateSuperClassMethodNoDefaultMethod
595
*
596
* interface I {
597
* public int m();
598
* }
599
*
600
* public class A {
601
* private int m() { return 1; }
602
* }
603
*
604
* public class B extends A implements I {}
605
*
606
* public class C extends B {
607
* public int m() { return 2; }
608
* }
609
*
610
* TEST: { B b = new C(); b.m()I throws IllegalAccessError; }
611
*/
612
public void testPrivateSuperClassMethodNoDefaultMethod(TestBuilder b) {
613
ConcreteClass A = b.clazz("A")
614
.concreteMethod("m", "()I").private_().returns(1).build()
615
.build();
616
617
Interface I = b.intf("I")
618
.abstractMethod("m", "()I").public_().build()
619
.build();
620
621
ConcreteClass B = b.clazz("B").extend(A).implement(I).build();
622
623
ConcreteClass C = b.clazz("C").extend(B)
624
.concreteMethod("m", "()I").public_().returns(2).build()
625
.build();
626
627
b.test().privateCallSite(B, C, "m", "()I").throws_(IllegalAccessError.class).done();
628
}
629
630
/*
631
* testPrivateSuperClassMethodDefaultMethod
632
*
633
* interface I {
634
* public default int m() { return 3; }
635
* }
636
*
637
* public class A {
638
* private int m() { return 1; }
639
* }
640
*
641
* public class B extends A implements I {}
642
*
643
* public class C extends B {
644
* public int m() { return 2; }
645
* }
646
*
647
* TEST: { B b = new C(); b.m()I throws IllegalAccessError; }
648
*/
649
public void testPrivateSuperClassMethodDefaultMethod(TestBuilder b) {
650
ConcreteClass A = b.clazz("A")
651
.concreteMethod("m", "()I").private_().returns(1).build()
652
.build();
653
654
Interface I = b.intf("I")
655
.defaultMethod("m", "()I").public_().returns(3).build()
656
.build();
657
658
ConcreteClass B = b.clazz("B").extend(A).implement(I).build();
659
660
ConcreteClass C = b.clazz("C").extend(B)
661
.concreteMethod("m", "()I").public_().returns(2).build()
662
.build();
663
664
b.test().privateCallSite(B, C, "m", "()I").throws_(IllegalAccessError.class).done();
665
}
666
667
/*
668
* testPrivateSuperClassMethodDefaultMethodNoOverride
669
*
670
* interface I {
671
* public default int m() { return 3; }
672
* }
673
*
674
* public class A {
675
* private int m() { return 1; }
676
* }
677
*
678
* public class B extends A implements I {}
679
*
680
* public class C extends B { }
681
*
682
* TEST: { B b = new C(); b.m()I throws IllegalAccessError; }
683
*/
684
public void testPrivateSuperClassMethodDefaultMethodNoOverride(TestBuilder b) {
685
ConcreteClass A = b.clazz("A")
686
.concreteMethod("m", "()I").private_().returns(1).build()
687
.build();
688
689
Interface I = b.intf("I")
690
.defaultMethod("m", "()I").public_().returns(3).build()
691
.build();
692
693
ConcreteClass B = b.clazz("B").extend(A).implement(I).build();
694
695
ConcreteClass C = b.clazz("C").extend(B).build();
696
697
b.test().privateCallSite(B, C, "m", "()I").throws_(IllegalAccessError.class).done();
698
}
699
}
700
701