Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/runtime/defmeth/StaticMethodsTest.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.StaticMethodsTest
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.data.*;
45
import vm.runtime.defmeth.shared.builder.TestBuilder;
46
import vm.runtime.defmeth.shared.annotation.NotApplicableFor;
47
48
import static jdk.internal.org.objectweb.asm.Opcodes.*;
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 static methods in interfaces.
55
*/
56
public class StaticMethodsTest extends DefMethTest {
57
58
public static void main(String[] args) {
59
DefMethTest.runTest(StaticMethodsTest.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
// static method in interface
67
/*
68
* testStaticMethod
69
*
70
* interface I {
71
* default static public int m() { return 1; }
72
* }
73
*
74
* class C implements I {}
75
*/
76
public void testStaticMethod(TestBuilder b) {
77
Interface I = b.intf("I")
78
.defaultMethod("m", "()I")
79
.static_().public_().returns(1).build()
80
.build();
81
82
ConcreteClass C = b.clazz("C").implement(I).build();
83
84
b.test().staticCallSite(I, "m", "()I").returns(1).done();
85
b.test().staticCallSite(C, "m", "()I").throws_(NoSuchMethodError.class).done();
86
}
87
88
// invoke[virtual|interface|special] from same/subintf
89
/*
90
* testInvokeVirtual
91
*
92
* interface I {
93
* default static public int staticM() { return 1; }
94
* default public int m() { return ((I)this).staticM(); }
95
* }
96
*
97
* class C implements I {}
98
*/
99
public void testInvokeVirtual(TestBuilder b) {
100
Interface I = b.intf("I")
101
.defaultMethod("staticM", "()I")
102
.static_().public_().returns(1).build()
103
104
// force an invokevirtual MR of staticM()
105
.defaultMethod("m", "()I")
106
.invoke(VIRTUAL, b.intfByName("I"), null, "staticM", "()I", METHODREF).build()
107
.build();
108
109
ConcreteClass C = b.clazz("C").implement(I).build();
110
111
b.test().staticCallSite(I, "staticM", "()I").returns(1).done();
112
113
b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
114
b.test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
115
}
116
117
/*
118
* testInvokeIntf
119
*
120
* interface I {
121
* default static public int staticM() { return 1; }
122
* default public int m() { return ((I)this).staticM(); }
123
* }
124
*
125
* class C implements I {}
126
*/
127
public void testInvokeIntf(TestBuilder b) {
128
Interface I = b.intf("I")
129
.defaultMethod("staticM", "()I")
130
.static_().public_().returns(1).build()
131
132
.defaultMethod("m", "()I")
133
.invoke(INTERFACE, b.intfByName("I"), null, "staticM", "()I", CALLSITE).build()
134
.build();
135
136
ConcreteClass C = b.clazz("C").implement(I).build();
137
138
b.test().staticCallSite(I, "staticM", "()I").returns(1).done();
139
140
b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
141
b.test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
142
}
143
144
/*
145
* testInvokeSpecial
146
*
147
* interface I {
148
* default static public int staticM() { return 1; }
149
* default public int m() { return I.super.staticM(); }
150
* }
151
*
152
* class C implements I {}
153
*/
154
public void testInvokeSpecial(TestBuilder b) {
155
Interface I = b.intf("I")
156
.defaultMethod("staticM", "()I")
157
.static_().public_().returns(1).build()
158
159
.defaultMethod("m", "()I")
160
.invoke(SPECIAL, b.intfByName("I"), null, "staticM", "()I", CALLSITE).build()
161
.build();
162
163
ConcreteClass C = b.clazz("C").implement(I).build();
164
165
b.test().staticCallSite(I, "staticM", "()I").returns(1).done();
166
167
b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
168
b.test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
169
}
170
171
/*
172
* testStaticVsDefault
173
*
174
* interface I {
175
* default static public int m() { return 1; }
176
* default public int m() { return 2; }
177
* }
178
*
179
* class C implements I {}
180
*/
181
public void testStaticVsDefault(TestBuilder b) {
182
Interface I = b.intf("I")
183
.defaultMethod("m", "()I")
184
.static_().public_().returns(1).build()
185
.defaultMethod("m", "()I")
186
.public_().returns(2).build()
187
.build();
188
189
ConcreteClass C = b.clazz("C").implement(I).build();
190
191
b.test().staticCallSite(I, "m", "()I").throws_(ClassFormatError.class).done();
192
193
// FIXME: throws exception during an attempt to lookup Test2.test() method
194
195
// Invalid test. ClassFormatError is thrown at verification time, rather
196
// than execution time.
197
// .test().callSite(I, C, "m", "()I").throws_(ClassFormatError.class).done()
198
b.test().callSite(C, C, "m", "()I").throws_(ClassFormatError.class).done();
199
}
200
201
// call static method from default method
202
/*
203
* testInvokeFromDefaultMethod
204
*
205
* interface I {
206
* default static public int staticPublicM() { return 1; }
207
* default public int invokePublic() { return I.staticPublicM(); }
208
* default static private int staticPrivateM() { return 1; }
209
* default public int invokePrivate() { return I.staticPrivateM(); }
210
* }
211
*
212
* class C implements I {}
213
*/
214
public void testInvokeFromDefaultMethod(TestBuilder b) {
215
Interface I = b.intf("I")
216
.defaultMethod("staticPublicM", "()I")
217
.static_().public_().returns(1).build()
218
.defaultMethod("invokePublic", "()I")
219
.invokeStatic(b.intfByName("I"), "staticPublicM", "()I").build()
220
221
.defaultMethod("staticPrivateM", "()I")
222
.static_().private_().returns(1).build()
223
.defaultMethod("invokePrivate", "()I")
224
.invokeStatic(b.intfByName("I"), "staticPrivateM", "()I").build()
225
.build();
226
227
ConcreteClass C = b.clazz("C").implement(I).build();
228
229
// call static method from another class
230
b.test().staticCallSite(I, "staticPublicM", "()I").returns(1).done()
231
232
.test().callSite(I, "staticPrivateM", "()I", ACC_STATIC | ACC_PRIVATE).throws_(IllegalAccessError.class).done()
233
234
// call public static method from default method
235
.test().callSite(I, C, "invokePublic", "()I").returns(1).done()
236
.test().callSite(C, C, "invokePublic", "()I").returns(1).done()
237
238
// call private static method from default method
239
.test().callSite(I, C, "invokePrivate", "()I").returns(1).done()
240
.test().callSite(C, C, "invokePrivate", "()I").returns(1).done();
241
}
242
243
// call static method from implementing subclass
244
/*
245
* testInvokeFromSubclass
246
*
247
* interface I {
248
* default static public int staticPublicM() { return 1; }
249
* default static private int staticPrivateM() { return 1; }
250
* }
251
*
252
* class C implements I {
253
* public int invokePublic() { return I.staticPublicM(); }
254
* public int invokePrivate() { return I.staticPublicM(); }
255
*
256
* I.staticPublicM(); ==> returns 1;
257
* I.staticPrivateM(); ==> Either NSME or IAE depending on execution mode
258
* C c = new C(); c.invokePublic(); ==> returns 1 or if -ver < 52 IAE or VerifyError
259
* C c = new C(); c.invokePrivate() ==> IAE or if -ver < 52, IAE or VerifyError
260
* }
261
*/
262
@NotApplicableFor(modes = { REDEFINITION }) // Can't redefine a class that gets error during loading
263
public void testInvokeFromSubclass(TestBuilder b) {
264
Interface I = b.intf("I")
265
.defaultMethod("staticPublicM", "()I")
266
.static_().public_().returns(1).build()
267
268
.defaultMethod("staticPrivateM", "()I")
269
.static_().private_().returns(1).build()
270
.build();
271
272
ConcreteClass C = b.clazz("C").implement(I)
273
.concreteMethod("invokePublic", "()I")
274
.invokeStatic(b.intfByName("I"), "staticPublicM", "()I").build()
275
.concreteMethod("invokePrivate", "()I")
276
.invokeStatic(b.intfByName("I"), "staticPrivateM", "()I").build()
277
.build();
278
279
// call static method from another class
280
b.test().staticCallSite(I, "staticPublicM", "()I").returns(1).done()
281
.test().callSite(I, "staticPrivateM", "()I", ACC_STATIC | ACC_PRIVATE).throws_(IllegalAccessError.class).done();
282
283
// call static method from implementing subclass
284
if (factory.getVer() >=52) {
285
b.test().callSite(C, C, "invokePublic", "()I").returns(1).done()
286
.test().callSite(C, C, "invokePrivate", "()I").throws_(IllegalAccessError.class).done();
287
} else {
288
// invokestatic IMR - not supported for ver < 52
289
b.test().callSite(C, C, "invokePublic", "()I").throws_(VerifyError.class).done()
290
.test().callSite(C, C, "invokePrivate", "()I").throws_(VerifyError.class).done();
291
}
292
}
293
294
// static method doesn't participate in default method analysis:
295
// method overriding
296
/*
297
* testNotInherited
298
*
299
* interface I {
300
* default static public int m() { return 1; }
301
* }
302
*
303
* class C implements I {}
304
*/
305
public void testNotInherited(TestBuilder b) {
306
Interface I = b.intf("I")
307
.defaultMethod("m", "()I")
308
.static_().public_().returns(1).build()
309
.build();
310
311
ConcreteClass C = b.clazz("C").implement(I).build();
312
313
b.test().staticCallSite(I, "m", "()I").returns(1).done();
314
315
b.test().callSite(C, C, "m", "()I").throws_(NoSuchMethodError.class).done();
316
317
if (factory.getExecutionMode().equals("REFLECTION")) {
318
b.test().callSite(I, C, "m", "()I").returns(1).done();
319
} else {
320
// invokeinterface to static method ==> ICCE
321
b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
322
}
323
}
324
325
/*
326
* testDefaultVsConcrete
327
*
328
* interface I {
329
* default static public int m() { return 1; }
330
* }
331
*
332
* class C implements I {
333
* public int m() { return 2; }
334
* }
335
* TEST: I o = new C(); o.m()I throws ICCE
336
* TEST: C o = new C(); o.m()I == 2
337
*/
338
public void testDefaultVsConcrete(TestBuilder b) {
339
Interface I = b.intf("I")
340
.defaultMethod("m", "()I")
341
.static_().public_().returns(1).build()
342
.build();
343
344
ConcreteClass C = b.clazz("C").implement(I)
345
.concreteMethod("m", "()I").returns(2).build()
346
.build();
347
348
if (factory.getExecutionMode().equals("REFLECTION")) {
349
b.test().callSite(I, C, "m", "()I").returns(1).done();
350
} else {
351
// invokeinterface to static method ==> ICCE
352
b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
353
}
354
355
b.test().callSite(C, C, "m", "()I").returns(2).done();
356
}
357
358
/*
359
* TEST: StaticMethodsTest.testOverrideStatic
360
*
361
* interface I {
362
* default static public int m() { return 1; }
363
* }
364
*
365
* interface J extends I {
366
* default public int m() { return 2; }
367
* }
368
*
369
* class C implements J {
370
* }
371
*/
372
public void testOverrideStatic(TestBuilder b) {
373
Interface I = b.intf("I")
374
.defaultMethod("m", "()I")
375
.static_().public_().returns(1).build()
376
.build();
377
378
Interface J = b.intf("J").extend(I)
379
.defaultMethod("m", "()I")
380
.returns(2).build()
381
.build();
382
383
ConcreteClass C = b.clazz("C").implement(J).build();
384
385
b.test().staticCallSite(I, "m", "()I").returns(1).done();
386
387
b.test().callSite(J, C, "m", "()I").returns(2).done();
388
b.test().callSite(C, C, "m", "()I").returns(2).done();
389
390
if (factory.getExecutionMode().equals("REFLECTION")) {
391
b.test().callSite(I, C, "m", "()I").returns(1).done();
392
} else {
393
b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
394
}
395
}
396
397
/*
398
* testOverrideDefault
399
*
400
* interface I {
401
* default public int m() { return 1; }
402
* }
403
*
404
* interface J extends I {
405
* default static public int m() { return 2; }
406
* }
407
*
408
* class C implements J {}
409
*
410
* TEST: I o = new C(); o.m()I == 1
411
* TEST: J o = new C(); o.m()I == ICCE
412
* TEST: C o = new C(); o.m()I == 1
413
*/
414
public void testOverrideDefault(TestBuilder b) {
415
Interface I = b.intf("I")
416
.defaultMethod("m", "()I")
417
.returns(1).build()
418
.build();
419
420
Interface J = b.intf("J").extend(I)
421
.defaultMethod("m", "()I")
422
.static_().public_().returns(2).build()
423
.build();
424
425
ConcreteClass C = b.clazz("C").implement(J).build();
426
427
b.test().callSite(I, C, "m", "()I").returns(1).done();
428
b.test().callSite(C, C, "m", "()I").returns(1).done();
429
430
if (factory.getExecutionMode().equals("REFLECTION")) {
431
// Reflection correctly finds the static method defined in J and
432
// calls it with invokestatic.
433
b.test().callSite(J, C, "m", "()I").returns(2).done();
434
} else {
435
b.test().callSite(J, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
436
}
437
}
438
439
/*
440
* testReabstract
441
*
442
* interface I {
443
* default static public int m() { return 1; }
444
* }
445
*
446
* interface J extends I {
447
* abstract public int m();
448
* }
449
*
450
* class C implements J {}
451
*
452
* TEST: I o = new C(); o.m()I throws ICCE
453
* -mode reflect returns 1
454
* TEST: J o = new C(); o.m()I throws AME
455
* TEST: C o = new C(); o.m()I throws AME
456
*/
457
public void testReabstract(TestBuilder b) {
458
Interface I = b.intf("I")
459
.defaultMethod("m", "()I")
460
.static_().public_().returns(1).build()
461
.build();
462
463
Interface J = b.intf("J").extend(I)
464
.abstractMethod("m", "()I").build()
465
.build();
466
467
ConcreteClass C = b.clazz("C").implement(J).build();
468
469
if (factory.getExecutionMode().equals("REFLECTION")) {
470
b.test().callSite(I, C, "m", "()I").returns(1).done();
471
} else {
472
b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
473
}
474
475
b.test().callSite(J, C, "m", "()I").throws_(AbstractMethodError.class).done();
476
b.test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done();
477
}
478
479
/*
480
* testOverrideAbstract
481
*
482
* interface I {
483
* abstract public int m();
484
* }
485
*
486
* interface J extends I {
487
* default static public int m() { return 1; }
488
* }
489
*
490
* class C implements J {}
491
*
492
* TEST: I o = new C(); o.m()I throws AME
493
* TEST: J o = new C(); o.m()I throws ICCE
494
* -mode reflect returns 1
495
* TEST: C o = new C(); o.m()I throws AME
496
*/
497
public void testOverrideAbstract(TestBuilder b) {
498
Interface I = b.intf("I")
499
.abstractMethod("m", "()I").build()
500
.build();
501
502
Interface J = b.intf("J").extend(I)
503
.defaultMethod("m", "()I")
504
.static_().public_().returns(1).build()
505
.build();
506
507
ConcreteClass C = b.clazz("C").implement(J).build();
508
509
b.test().callSite(I, C, "m", "()I").throws_(AbstractMethodError.class).done();
510
b.test().callSite(C, C, "m", "()I").throws_(AbstractMethodError.class).done();
511
512
if (factory.getExecutionMode().equals("REFLECTION")) {
513
b.test().callSite(J, C, "m", "()I").returns(1).done();
514
} else {
515
b.test().callSite(J, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
516
}
517
}
518
519
/*
520
* testInheritedDefault
521
*
522
* interface I {
523
* default static public int m() { return 1; }
524
* }
525
*
526
* class B implements I {}
527
*
528
* class C extends B {}
529
*
530
* TEST: I o = new C(); o.m()I throws IncompatibleClassChangeError
531
* -mode reflect returns 1
532
* TEST: B o = new C(); o.m()I throws NoSuchMethodError
533
* TEST: C o = new C(); o.m()I throws NoSuchMethodError
534
*/
535
public void testInheritedDefault(TestBuilder b) {
536
Interface I = b.intf("I")
537
.defaultMethod("m", "()I")
538
.static_().public_().returns(1).build()
539
.build();
540
541
ConcreteClass B = b.clazz("B").implement(I).build();
542
ConcreteClass C = b.clazz("C").extend(B).build();
543
544
b.test().callSite(B, C, "m","()I").throws_(NoSuchMethodError.class).done();
545
b.test().callSite(C, C, "m","()I").throws_(NoSuchMethodError.class).done();
546
547
if (factory.getExecutionMode().equals("REFLECTION")) {
548
b.test().callSite(I, C, "m","()I").returns(1).done();
549
} else {
550
b.test().callSite(I, C, "m","()I").throws_(IncompatibleClassChangeError.class).done();
551
}
552
}
553
554
/*
555
* testDefaultVsConcreteInherited
556
*
557
* interface I {
558
* default static public int m() { return 1; }
559
* }
560
*
561
* class B {
562
* public int m() { return 2; }
563
* }
564
*
565
* class C extends B implements I {}
566
*
567
*/
568
public void testDefaultVsConcreteInherited(TestBuilder b) {
569
Interface I = b.intf("I")
570
.defaultMethod("m", "()I")
571
.static_().public_().returns(1).build()
572
.build();
573
574
ConcreteClass B = b.clazz("B")
575
.concreteMethod("m", "()I").returns(2).build()
576
.build();
577
578
ConcreteClass C = b.clazz("C").extend(B).implement(I).build();
579
580
b.test().staticCallSite(I, "m","()I").returns(1).done();
581
582
b.test().callSite(B, C, "m","()I").returns(2).done();
583
b.test().callSite(C, C, "m","()I").returns(2).done();
584
585
if (factory.getExecutionMode().equals("REFLECTION")) {
586
b.test().callSite(I, C, "m","()I").returns(1).done();
587
} else {
588
b.test().callSite(I, C, "m","()I").throws_(IncompatibleClassChangeError.class).done();
589
}
590
}
591
592
/*
593
* testDefaultVsStaticConflict
594
*
595
* interface I {
596
* default static public int m() { return 1; }
597
* }
598
*
599
* interface J {
600
* default public int m() { return 2; }
601
* }
602
*
603
* class C implements I, J {}
604
*
605
* TEST: I o = new C(); o.m()I throws ICCE
606
* -mode reflect returns 1
607
* TEST: J o = new C(); o.m()I == 2
608
* TEST: C o = new C(); o.m()I == 2
609
*/
610
public void testDefaultVsStaticConflict(TestBuilder b) {
611
Interface I = b.intf("I")
612
.defaultMethod("m", "()I")
613
.static_().public_().returns(1).build()
614
.build();
615
616
Interface J = b.intf("J")
617
.defaultMethod("m", "()I").returns(2).build()
618
.build();
619
620
ConcreteClass C = b.clazz("C").implement(I,J).build();
621
622
b.test().callSite(J, C, "m", "()I").returns(2).done();
623
b.test().callSite(C, C, "m", "()I").returns(2).done();
624
625
if (factory.getExecutionMode().equals("REFLECTION")) {
626
b.test().callSite(I, C, "m", "()I").returns(1).done();
627
} else {
628
b.test().callSite(I, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
629
}
630
}
631
632
/*
633
* testStaticSuperClassVsDefaultSuperInterface
634
*
635
* interface I {
636
* default public int m() { return 1; }
637
* }
638
*
639
* class A {
640
* public static int m() { return 2; }
641
* }
642
*
643
* class C extends A implements I {}
644
*
645
* TEST: C o = new C(); o.m()I throws ICCE
646
* -mode reflect returns 2
647
* TEST: I o = new C(); o.m()I == 1
648
*/
649
public void testStaticSuperClassVsDefaultSuperInterface(TestBuilder b) {
650
Interface I = b.intf("I")
651
.defaultMethod("m", "()I")
652
.public_().returns(1).build()
653
.build();
654
655
ConcreteClass A = b.clazz("A")
656
.concreteMethod("m", "()I")
657
.static_().public_().returns(2).build()
658
.build();
659
660
ConcreteClass C = b.clazz("C").extend(A).implement(I).build();
661
662
b.test().callSite(I, C, "m", "()I").returns(1).done();
663
664
if (factory.getExecutionMode().equals("REFLECTION")) {
665
b.test().callSite(C, C, "m", "()I").returns(2).done();
666
} else {
667
b.test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
668
}
669
}
670
671
/*
672
* testStaticLocalVsDefaultSuperInterface
673
*
674
* interface I {
675
* default public int m() { return 1; }
676
* }
677
*
678
* class A implements I {
679
* public static int m() { return 2; }
680
* }
681
*
682
* class C extends A implements I {}
683
*
684
* TEST: A o = new A(); o.m()I throws ICCE
685
* -mode reflect returns 2
686
* TEST: I o = new A(); o.m()I == 1
687
*/
688
public void testStaticLocalVsDefaultSuperInterface(TestBuilder b) {
689
Interface I = b.intf("I")
690
.defaultMethod("m", "()I")
691
.public_().returns(1).build()
692
.build();
693
694
ConcreteClass A = b.clazz("A").implement(I)
695
.concreteMethod("m", "()I")
696
.static_().public_().returns(2).build()
697
.build();
698
699
ConcreteClass C = b.clazz("C").extend(A).implement(I).build();
700
701
b.test().callSite(I, A, "m", "()I").returns(1).done();
702
b.test().callSite(I, C, "m", "()I").returns(1).done();
703
704
if (factory.getExecutionMode().equals("REFLECTION")) {
705
b.test().callSite(A, A, "m", "()I").returns(2).done();
706
b.test().callSite(C, C, "m", "()I").returns(2).done();
707
} else {
708
b.test().callSite(C, C, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
709
b.test().callSite(A, A, "m", "()I").throws_(IncompatibleClassChangeError.class).done();
710
}
711
}
712
713
/*
714
* testConflictingDefaultsandStaticMethod
715
* @bug 8033150
716
*
717
* interface I {
718
* default public int m() { return 1; }
719
* }
720
*
721
* interface J {
722
* default public int m() { return 2; }
723
* }
724
*
725
* class A implements I, J {
726
* public static int m() { return 3; }
727
* }
728
*
729
* class C extends A {}
730
*
731
* TEST: C.m(); should call A.m, return value = 3
732
*/
733
public void testConflictingDefaultsandStaticMethod(TestBuilder b) {
734
Interface I = b.intf("I")
735
.defaultMethod("m", "()I")
736
.public_().returns(1).build()
737
.build();
738
739
Interface J = b.intf("J")
740
.defaultMethod("m", "()I")
741
.public_().returns(2).build()
742
.build();
743
744
ConcreteClass A = b.clazz("A").implement(I,J)
745
.concreteMethod("m", "()I")
746
.static_().public_().returns(3).build()
747
.build();
748
749
ConcreteClass C = b.clazz("C").extend(A).build();
750
751
b.test().staticCallSite(C, "m", "()I").returns(3).done();
752
}
753
}
754
755