|
Lines 540-580
Link Here
|
| 540 |
"Syntax error on token \"(\", Resources expected after this token\n" + |
540 |
"Syntax error on token \"(\", Resources expected after this token\n" + |
| 541 |
"----------\n"); |
541 |
"----------\n"); |
| 542 |
} |
542 |
} |
| 543 |
public void test019() { |
543 |
public void test020() { |
|
|
544 |
this.runNegativeTest( |
| 545 |
new String[] { |
| 546 |
"X.java", |
| 547 |
"public class X implements AutoCloseable {\n" + |
| 548 |
" public static void main(String [] args) {\n" + |
| 549 |
" try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + |
| 550 |
" throw new XXException();\n" + |
| 551 |
" } catch (XException x) {\n" + |
| 552 |
" } catch (YException y) {\n" + |
| 553 |
" } catch (ZException z) {\n" + |
| 554 |
" } finally {\n" + |
| 555 |
" }\n" + |
| 556 |
" }\n" + |
| 557 |
" public X() throws XException {\n" + |
| 558 |
" throw new XException();\n" + |
| 559 |
" }\n" + |
| 560 |
" public void close() throws XXException {\n" + |
| 561 |
" throw new XXException();\n" + |
| 562 |
" }\n" + |
| 563 |
"}\n" + |
| 564 |
"class Y implements AutoCloseable {\n" + |
| 565 |
" public Y() throws YException {\n" + |
| 566 |
" throw new YException();\n" + |
| 567 |
" }\n" + |
| 568 |
" public void close() throws YYException {\n" + |
| 569 |
" throw new YYException();\n" + |
| 570 |
" }\n" + |
| 571 |
"}\n" + |
| 572 |
"class Z implements AutoCloseable {\n" + |
| 573 |
" public Z() throws ZException {\n" + |
| 574 |
" throw new ZException();\n" + |
| 575 |
" }\n" + |
| 576 |
" public void close() throws ZZException {\n" + |
| 577 |
" throw new ZZException();\n" + |
| 578 |
" }\n" + |
| 579 |
"}\n" + |
| 580 |
"class XException extends Exception {}\n" + |
| 581 |
"class XXException extends Exception {}\n" + |
| 582 |
"class YException extends Exception {}\n" + |
| 583 |
"class YYException extends Exception {}\n" + |
| 584 |
"class ZException extends Exception {}\n" + |
| 585 |
"class ZZException extends Exception {}\n" |
| 586 |
}, |
| 587 |
"----------\n" + |
| 588 |
"1. ERROR in X.java (at line 3)\n" + |
| 589 |
" try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + |
| 590 |
" ^^^^^^^^^^^^\n" + |
| 591 |
"Unhandled exception type XXException\n" + |
| 592 |
"----------\n" + |
| 593 |
"2. ERROR in X.java (at line 3)\n" + |
| 594 |
" try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + |
| 595 |
" ^^^^^^^^^^^^\n" + |
| 596 |
"Unhandled exception type YYException\n" + |
| 597 |
"----------\n" + |
| 598 |
"3. ERROR in X.java (at line 3)\n" + |
| 599 |
" try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + |
| 600 |
" ^\n" + |
| 601 |
"Unhandled exception type ZZException\n" + |
| 602 |
"----------\n" + |
| 603 |
"4. ERROR in X.java (at line 4)\n" + |
| 604 |
" throw new XXException();\n" + |
| 605 |
" ^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
| 606 |
"Unhandled exception type XXException\n" + |
| 607 |
"----------\n" + |
| 608 |
"5. WARNING in X.java (at line 34)\n" + |
| 609 |
" class XException extends Exception {}\n" + |
| 610 |
" ^^^^^^^^^^\n" + |
| 611 |
"The serializable class XException does not declare a static final serialVersionUID field of type long\n" + |
| 612 |
"----------\n" + |
| 613 |
"6. WARNING in X.java (at line 35)\n" + |
| 614 |
" class XXException extends Exception {}\n" + |
| 615 |
" ^^^^^^^^^^^\n" + |
| 616 |
"The serializable class XXException does not declare a static final serialVersionUID field of type long\n" + |
| 617 |
"----------\n" + |
| 618 |
"7. WARNING in X.java (at line 36)\n" + |
| 619 |
" class YException extends Exception {}\n" + |
| 620 |
" ^^^^^^^^^^\n" + |
| 621 |
"The serializable class YException does not declare a static final serialVersionUID field of type long\n" + |
| 622 |
"----------\n" + |
| 623 |
"8. WARNING in X.java (at line 37)\n" + |
| 624 |
" class YYException extends Exception {}\n" + |
| 625 |
" ^^^^^^^^^^^\n" + |
| 626 |
"The serializable class YYException does not declare a static final serialVersionUID field of type long\n" + |
| 627 |
"----------\n" + |
| 628 |
"9. WARNING in X.java (at line 38)\n" + |
| 629 |
" class ZException extends Exception {}\n" + |
| 630 |
" ^^^^^^^^^^\n" + |
| 631 |
"The serializable class ZException does not declare a static final serialVersionUID field of type long\n" + |
| 632 |
"----------\n" + |
| 633 |
"10. WARNING in X.java (at line 39)\n" + |
| 634 |
" class ZZException extends Exception {}\n" + |
| 635 |
" ^^^^^^^^^^^\n" + |
| 636 |
"The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" + |
| 637 |
"----------\n"); |
| 638 |
} |
| 639 |
public void test021() { |
| 640 |
this.runNegativeTest( |
| 641 |
new String[] { |
| 642 |
"X.java", |
| 643 |
"public class X {\n" + |
| 644 |
" public void method1(){\n" + |
| 645 |
" try (Y i = null) {\n" + |
| 646 |
" System.out.println();\n" + |
| 647 |
" }\n" + |
| 648 |
" }\n" + |
| 649 |
"}\n" + |
| 650 |
"class Y {\n" + |
| 651 |
" public void close () {}\n" + |
| 652 |
"}", |
| 653 |
}, |
| 654 |
"----------\n" + |
| 655 |
"1. ERROR in X.java (at line 3)\n" + |
| 656 |
" try (Y i = null) {\n" + |
| 657 |
" ^\n" + |
| 658 |
"The resource type Y has to be a subclass of java.lang.AutoCloseable \n" + |
| 659 |
"----------\n"); |
| 660 |
} |
| 661 |
public void test022() { |
| 544 |
this.runNegativeTest( |
662 |
this.runNegativeTest( |
| 545 |
new String[] { |
663 |
new String[] { |
| 546 |
"X.java", |
664 |
"X.java", |
| 547 |
"public class X {\n" + |
665 |
"public class X {\n" + |
|
|
666 |
" public void method1(){\n" + |
| 667 |
" try (Y i = null) {\n" + |
| 668 |
" System.out.println();\n" + |
| 669 |
" }\n" + |
| 670 |
" }\n" + |
| 671 |
"}\n" + |
| 672 |
"class Y implements AutoCloseable {\n" + |
| 673 |
" public int close () { return 0; }\n" + |
| 674 |
"}", |
| 675 |
}, |
| 676 |
"----------\n" + |
| 677 |
"1. ERROR in X.java (at line 9)\n" + |
| 678 |
" public int close () { return 0; }\n" + |
| 679 |
" ^^^\n" + |
| 680 |
"The return type is incompatible with AutoCloseable.close()\n" + |
| 681 |
"----------\n"); |
| 682 |
} |
| 683 |
public void test023() { |
| 684 |
this.runNegativeTest( |
| 685 |
new String[] { |
| 686 |
"X.java", |
| 687 |
"public class X {\n" + |
| 688 |
" public void method1(){\n" + |
| 689 |
" try (Y i = null) {\n" + |
| 690 |
" System.out.println();\n" + |
| 691 |
" }\n" + |
| 692 |
" }\n" + |
| 693 |
"}\n" + |
| 694 |
"class Y implements AutoCloseable {\n" + |
| 695 |
" public void close () throws Blah {}\n" + |
| 696 |
"}\n" + |
| 697 |
"class Blah extends Throwable {}\n", |
| 698 |
}, |
| 699 |
"----------\n" + |
| 700 |
"1. ERROR in X.java (at line 3)\n" + |
| 701 |
" try (Y i = null) {\n" + |
| 702 |
" ^\n" + |
| 703 |
"Unhandled exception type Blah\n" + |
| 704 |
"----------\n" + |
| 705 |
"2. ERROR in X.java (at line 9)\n" + |
| 706 |
" public void close () throws Blah {}\n" + |
| 707 |
" ^^^^^^^^^^^^^^^^^^^^\n" + |
| 708 |
"Exception Blah is not compatible with throws clause in AutoCloseable.close()\n" + |
| 709 |
"----------\n" + |
| 710 |
"3. WARNING in X.java (at line 11)\n" + |
| 711 |
" class Blah extends Throwable {}\n" + |
| 712 |
" ^^^^\n" + |
| 713 |
"The serializable class Blah does not declare a static final serialVersionUID field of type long\n" + |
| 714 |
"----------\n"); |
| 715 |
} |
| 716 |
public void test024() { |
| 717 |
this.runNegativeTest( |
| 718 |
new String[] { |
| 719 |
"X.java", |
| 720 |
"public class X implements AutoCloseable {\n" + |
| 548 |
" public static void main(String [] args) {\n" + |
721 |
" public static void main(String [] args) {\n" + |
| 549 |
" try (Y y = null) {\n" + |
722 |
" try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + |
| 550 |
" } catch (Exception e) {\n" + |
723 |
" throw new XXException();\n" + |
| 551 |
" System.out.println(y); \n" + |
724 |
" } catch (XException x) {\n" + |
| 552 |
" } finally {\n" + |
725 |
" } catch (YException y) {\n" + |
| 553 |
" System.out.println(y); \n" + |
726 |
" } catch (ZException z) {\n" + |
| 554 |
" }\n" + |
727 |
" } catch (XXException x) {\n" + |
| 555 |
" System.out.println(y); \n" + |
728 |
" } catch (YYException y) {\n" + |
|
|
729 |
" } catch (ZZException z) {\n" + |
| 730 |
" } finally {\n" + |
| 731 |
" }\n" + |
| 732 |
" }\n" + |
| 733 |
" public X() throws XException {\n" + |
| 734 |
" throw new XException();\n" + |
| 735 |
" }\n" + |
| 736 |
" public void close() throws XXException {\n" + |
| 737 |
" throw new XXException();\n" + |
| 738 |
" }\n" + |
| 739 |
"}\n" + |
| 740 |
"class Y implements AutoCloseable {\n" + |
| 741 |
" public Y() throws YException {\n" + |
| 742 |
" throw new YException();\n" + |
| 743 |
" }\n" + |
| 744 |
" public void close() throws YYException {\n" + |
| 745 |
" throw new YYException();\n" + |
| 746 |
" }\n" + |
| 747 |
"}\n" + |
| 748 |
"class Z implements AutoCloseable {\n" + |
| 749 |
" public Z() throws ZException {\n" + |
| 750 |
" throw new ZException();\n" + |
| 751 |
" }\n" + |
| 752 |
" public void close() throws ZZException {\n" + |
| 753 |
" throw new ZZException();\n" + |
| 754 |
" }\n" + |
| 755 |
"}\n" + |
| 756 |
"class XException extends Exception {}\n" + |
| 757 |
"class XXException extends Exception {}\n" + |
| 758 |
"class YException extends Exception {}\n" + |
| 759 |
"class YYException extends Exception {}\n" + |
| 760 |
"class ZException extends Exception {}\n" + |
| 761 |
"class ZZException extends Exception {}\n" |
| 762 |
}, |
| 763 |
"----------\n" + |
| 764 |
"1. WARNING in X.java (at line 37)\n" + |
| 765 |
" class XException extends Exception {}\n" + |
| 766 |
" ^^^^^^^^^^\n" + |
| 767 |
"The serializable class XException does not declare a static final serialVersionUID field of type long\n" + |
| 768 |
"----------\n" + |
| 769 |
"2. WARNING in X.java (at line 38)\n" + |
| 770 |
" class XXException extends Exception {}\n" + |
| 771 |
" ^^^^^^^^^^^\n" + |
| 772 |
"The serializable class XXException does not declare a static final serialVersionUID field of type long\n" + |
| 773 |
"----------\n" + |
| 774 |
"3. WARNING in X.java (at line 39)\n" + |
| 775 |
" class YException extends Exception {}\n" + |
| 776 |
" ^^^^^^^^^^\n" + |
| 777 |
"The serializable class YException does not declare a static final serialVersionUID field of type long\n" + |
| 778 |
"----------\n" + |
| 779 |
"4. WARNING in X.java (at line 40)\n" + |
| 780 |
" class YYException extends Exception {}\n" + |
| 781 |
" ^^^^^^^^^^^\n" + |
| 782 |
"The serializable class YYException does not declare a static final serialVersionUID field of type long\n" + |
| 783 |
"----------\n" + |
| 784 |
"5. WARNING in X.java (at line 41)\n" + |
| 785 |
" class ZException extends Exception {}\n" + |
| 786 |
" ^^^^^^^^^^\n" + |
| 787 |
"The serializable class ZException does not declare a static final serialVersionUID field of type long\n" + |
| 788 |
"----------\n" + |
| 789 |
"6. WARNING in X.java (at line 42)\n" + |
| 790 |
" class ZZException extends Exception {}\n" + |
| 791 |
" ^^^^^^^^^^^\n" + |
| 792 |
"The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" + |
| 793 |
"----------\n"); |
| 794 |
} |
| 795 |
public void test025() { |
| 796 |
this.runNegativeTest( |
| 797 |
new String[] { |
| 798 |
"X.java", |
| 799 |
"public class X implements AutoCloseable {\n" + |
| 800 |
" public static void main(String [] args) {\n" + |
| 801 |
" try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + |
| 802 |
" throw new XXException();\n" + |
| 803 |
" } catch (XException x) {\n" + |
| 804 |
" } catch (YException y) {\n" + |
| 805 |
" } catch (ZException z) {\n" + |
| 806 |
" \n" + |
| 807 |
" }\n" + |
| 808 |
" }\n" + |
| 809 |
" public X() throws XException {\n" + |
| 810 |
" throw new XException();\n" + |
| 811 |
" }\n" + |
| 812 |
" public void close() throws XXException {\n" + |
| 813 |
" throw new XXException();\n" + |
| 814 |
" }\n" + |
| 815 |
"}\n" + |
| 816 |
"class Y implements AutoCloseable {\n" + |
| 817 |
" public Y() throws YException {\n" + |
| 818 |
" throw new YException();\n" + |
| 819 |
" }\n" + |
| 820 |
" public void close() throws YYException {\n" + |
| 821 |
" throw new YYException();\n" + |
| 822 |
" }\n" + |
| 823 |
"}\n" + |
| 824 |
"class Z implements AutoCloseable {\n" + |
| 825 |
" public Z() throws ZException {\n" + |
| 826 |
" throw new ZException();\n" + |
| 827 |
" }\n" + |
| 828 |
" public void close() throws ZZException {\n" + |
| 829 |
" throw new ZZException();\n" + |
| 830 |
" }\n" + |
| 831 |
"}\n" + |
| 832 |
"class XException extends Exception {}\n" + |
| 833 |
"class XXException extends Exception {}\n" + |
| 834 |
"class YException extends Exception {}\n" + |
| 835 |
"class YYException extends Exception {}\n" + |
| 836 |
"class ZException extends Exception {}\n" + |
| 837 |
"class ZZException extends Exception {}\n" |
| 838 |
}, |
| 839 |
"----------\n" + |
| 840 |
"1. ERROR in X.java (at line 3)\n" + |
| 841 |
" try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + |
| 842 |
" ^^^^^^^^^^^^\n" + |
| 843 |
"Unhandled exception type XXException\n" + |
| 844 |
"----------\n" + |
| 845 |
"2. ERROR in X.java (at line 3)\n" + |
| 846 |
" try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + |
| 847 |
" ^^^^^^^^^^^^\n" + |
| 848 |
"Unhandled exception type YYException\n" + |
| 849 |
"----------\n" + |
| 850 |
"3. ERROR in X.java (at line 3)\n" + |
| 851 |
" try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + |
| 852 |
" ^\n" + |
| 853 |
"Unhandled exception type ZZException\n" + |
| 854 |
"----------\n" + |
| 855 |
"4. ERROR in X.java (at line 4)\n" + |
| 856 |
" throw new XXException();\n" + |
| 857 |
" ^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
| 858 |
"Unhandled exception type XXException\n" + |
| 859 |
"----------\n" + |
| 860 |
"5. WARNING in X.java (at line 34)\n" + |
| 861 |
" class XException extends Exception {}\n" + |
| 862 |
" ^^^^^^^^^^\n" + |
| 863 |
"The serializable class XException does not declare a static final serialVersionUID field of type long\n" + |
| 864 |
"----------\n" + |
| 865 |
"6. WARNING in X.java (at line 35)\n" + |
| 866 |
" class XXException extends Exception {}\n" + |
| 867 |
" ^^^^^^^^^^^\n" + |
| 868 |
"The serializable class XXException does not declare a static final serialVersionUID field of type long\n" + |
| 869 |
"----------\n" + |
| 870 |
"7. WARNING in X.java (at line 36)\n" + |
| 871 |
" class YException extends Exception {}\n" + |
| 872 |
" ^^^^^^^^^^\n" + |
| 873 |
"The serializable class YException does not declare a static final serialVersionUID field of type long\n" + |
| 874 |
"----------\n" + |
| 875 |
"8. WARNING in X.java (at line 37)\n" + |
| 876 |
" class YYException extends Exception {}\n" + |
| 877 |
" ^^^^^^^^^^^\n" + |
| 878 |
"The serializable class YYException does not declare a static final serialVersionUID field of type long\n" + |
| 879 |
"----------\n" + |
| 880 |
"9. WARNING in X.java (at line 38)\n" + |
| 881 |
" class ZException extends Exception {}\n" + |
| 882 |
" ^^^^^^^^^^\n" + |
| 883 |
"The serializable class ZException does not declare a static final serialVersionUID field of type long\n" + |
| 884 |
"----------\n" + |
| 885 |
"10. WARNING in X.java (at line 39)\n" + |
| 886 |
" class ZZException extends Exception {}\n" + |
| 887 |
" ^^^^^^^^^^^\n" + |
| 888 |
"The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" + |
| 889 |
"----------\n"); |
| 890 |
} |
| 891 |
public void test026() { |
| 892 |
this.runNegativeTest( |
| 893 |
new String[] { |
| 894 |
"X.java", |
| 895 |
"public class X implements AutoCloseable {\n" + |
| 896 |
" public static void main(String [] args) {\n" + |
| 897 |
" try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" + |
| 898 |
" throw new XXException();\n" + |
| 899 |
" } catch (XException x) {\n" + |
| 900 |
" } catch (YException y) {\n" + |
| 901 |
" } catch (ZException z) {\n" + |
| 902 |
" } catch (XXException x) {\n" + |
| 903 |
" } catch (YYException y) {\n" + |
| 904 |
" } catch (ZZException z) {\n\n" + |
| 905 |
" }\n" + |
| 906 |
" }\n" + |
| 907 |
" public X() throws XException {\n" + |
| 908 |
" throw new XException();\n" + |
| 909 |
" }\n" + |
| 910 |
" public void close() throws XXException {\n" + |
| 911 |
" throw new XXException();\n" + |
| 556 |
" }\n" + |
912 |
" }\n" + |
| 557 |
"}\n" + |
913 |
"}\n" + |
| 558 |
"class Y implements AutoCloseable {\n" + |
914 |
"class Y implements AutoCloseable {\n" + |
| 559 |
" public void close() {\n" + |
915 |
" public Y() throws YException {\n" + |
|
|
916 |
" throw new YException();\n" + |
| 917 |
" }\n" + |
| 918 |
" public void close() throws YYException {\n" + |
| 919 |
" throw new YYException();\n" + |
| 560 |
" }\n" + |
920 |
" }\n" + |
| 561 |
"}\n" |
921 |
"}\n" + |
|
|
922 |
"class Z implements AutoCloseable {\n" + |
| 923 |
" public Z() throws ZException {\n" + |
| 924 |
" throw new ZException();\n" + |
| 925 |
" }\n" + |
| 926 |
" public void close() throws ZZException {\n" + |
| 927 |
" throw new ZZException();\n" + |
| 928 |
" }\n" + |
| 929 |
"}\n" + |
| 930 |
"class XException extends Exception {}\n" + |
| 931 |
"class XXException extends Exception {}\n" + |
| 932 |
"class YException extends Exception {}\n" + |
| 933 |
"class YYException extends Exception {}\n" + |
| 934 |
"class ZException extends Exception {}\n" + |
| 935 |
"class ZZException extends Exception {}\n" |
| 562 |
}, |
936 |
}, |
| 563 |
"----------\n" + |
937 |
"----------\n" + |
| 564 |
"1. ERROR in X.java (at line 5)\n" + |
938 |
"1. WARNING in X.java (at line 37)\n" + |
| 565 |
" System.out.println(y); \n" + |
939 |
" class XException extends Exception {}\n" + |
| 566 |
" ^\n" + |
940 |
" ^^^^^^^^^^\n" + |
| 567 |
"y cannot be resolved to a variable\n" + |
941 |
"The serializable class XException does not declare a static final serialVersionUID field of type long\n" + |
|
|
942 |
"----------\n" + |
| 943 |
"2. WARNING in X.java (at line 38)\n" + |
| 944 |
" class XXException extends Exception {}\n" + |
| 945 |
" ^^^^^^^^^^^\n" + |
| 946 |
"The serializable class XXException does not declare a static final serialVersionUID field of type long\n" + |
| 947 |
"----------\n" + |
| 948 |
"3. WARNING in X.java (at line 39)\n" + |
| 949 |
" class YException extends Exception {}\n" + |
| 950 |
" ^^^^^^^^^^\n" + |
| 951 |
"The serializable class YException does not declare a static final serialVersionUID field of type long\n" + |
| 952 |
"----------\n" + |
| 953 |
"4. WARNING in X.java (at line 40)\n" + |
| 954 |
" class YYException extends Exception {}\n" + |
| 955 |
" ^^^^^^^^^^^\n" + |
| 956 |
"The serializable class YYException does not declare a static final serialVersionUID field of type long\n" + |
| 568 |
"----------\n" + |
957 |
"----------\n" + |
| 569 |
"2. ERROR in X.java (at line 7)\n" + |
958 |
"5. WARNING in X.java (at line 41)\n" + |
| 570 |
" System.out.println(y); \n" + |
959 |
" class ZException extends Exception {}\n" + |
| 571 |
" ^\n" + |
960 |
" ^^^^^^^^^^\n" + |
| 572 |
"y cannot be resolved to a variable\n" + |
961 |
"The serializable class ZException does not declare a static final serialVersionUID field of type long\n" + |
| 573 |
"----------\n" + |
962 |
"----------\n" + |
| 574 |
"3. ERROR in X.java (at line 9)\n" + |
963 |
"6. WARNING in X.java (at line 42)\n" + |
| 575 |
" System.out.println(y); \n" + |
964 |
" class ZZException extends Exception {}\n" + |
| 576 |
" ^\n" + |
965 |
" ^^^^^^^^^^^\n" + |
| 577 |
"y cannot be resolved to a variable\n" + |
966 |
"The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" + |
| 578 |
"----------\n"); |
967 |
"----------\n"); |
| 579 |
} |
968 |
} |
| 580 |
public static Class testClass() { |
969 |
public static Class testClass() { |