|
18 | 18 |
|
19 | 19 | import java.util.Map; |
20 | 20 | import junit.framework.Test; |
| 21 | +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
21 | 22 | import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
22 | 23 |
|
23 | 24 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
24 | 25 | public class InitializationTests extends AbstractRegressionTest { |
25 | 26 |
|
| 27 | +static { |
| 28 | +// TESTS_NAMES = new String [] { "testIssue4416" }; |
| 29 | +} |
26 | 30 | public InitializationTests(String name) { |
27 | 31 | super(name); |
28 | 32 | } |
@@ -487,6 +491,93 @@ public void testBug383690() { |
487 | 491 | "The blank final field oStatic may not have been initialized\n" + |
488 | 492 | "----------\n"); |
489 | 493 | } |
| 494 | +// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4416 |
| 495 | +// Bogus error: The blank final field o may not have been initialized |
| 496 | +public void testIssue4416() { |
| 497 | + runConformTest(new String[] { |
| 498 | + "WrongNotInitialized.java", |
| 499 | + """ |
| 500 | + public class WrongNotInitialized { |
| 501 | + private final Object o; |
| 502 | +
|
| 503 | + public WrongNotInitialized(final Object o) { |
| 504 | + super(); |
| 505 | + this.o = o; |
| 506 | + } |
| 507 | +
|
| 508 | + public WrongNotInitialized() { |
| 509 | + this(new Object()); |
| 510 | + System.out.println(o.toString()); |
| 511 | + } |
| 512 | + } |
| 513 | + """ |
| 514 | + }); |
| 515 | +} |
| 516 | +// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4416 |
| 517 | +// Bogus error: The blank final field o may not have been initialized |
| 518 | +public void testIssue4416b() { |
| 519 | + runConformTest(new String[] { |
| 520 | + "Test.java", |
| 521 | + """ |
| 522 | + public class Test { |
| 523 | +
|
| 524 | + final int x; |
| 525 | +
|
| 526 | + Test(int x) { |
| 527 | + this.x = x; |
| 528 | + } |
| 529 | +
|
| 530 | + Test(Test a) { |
| 531 | + this(a.x); |
| 532 | + //this(1); |
| 533 | +
|
| 534 | + System.out.println(x); |
| 535 | + } |
| 536 | + } |
| 537 | + """ |
| 538 | + }); |
| 539 | +} |
| 540 | +// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4416 |
| 541 | +// Bogus error: The blank final field o may not have been initialized |
| 542 | +public void testIssue4416c() { |
| 543 | + if (this.complianceLevel < ClassFileConstants.JDK16) |
| 544 | + return; |
| 545 | + runConformTest(new String[] { |
| 546 | + "TestRecord.java", |
| 547 | + """ |
| 548 | + public record TestRecord(String a) |
| 549 | + { |
| 550 | + public TestRecord(int b) |
| 551 | + { |
| 552 | + this(String.valueOf(b)); |
| 553 | + System.out.println(a.length()); |
| 554 | + } |
| 555 | + } |
| 556 | + """ |
| 557 | + }); |
| 558 | +} |
| 559 | +// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4416 |
| 560 | +// Bogus error: The blank final field o may not have been initialized |
| 561 | +public void testIssue4416d() { |
| 562 | + runConformTest(new String[] { |
| 563 | + "Test.java", |
| 564 | + """ |
| 565 | + public class Test { |
| 566 | +
|
| 567 | + private final Object r; |
| 568 | +
|
| 569 | + Test() { |
| 570 | + this(Integer.valueOf(1)); |
| 571 | + r.hashCode(); |
| 572 | + } |
| 573 | +
|
| 574 | + Test(Object r) { |
| 575 | + this.r = r; |
| 576 | + } |
| 577 | + } |
| 578 | + """ |
| 579 | + }); |
| 580 | +} |
490 | 581 | public static Class testClass() { |
491 | 582 | return InitializationTests.class; |
492 | 583 | } |
|
0 commit comments