Lines 536-539
Link Here
|
536 |
}, |
536 |
}, |
537 |
""); // no specific success output string |
537 |
""); // no specific success output string |
538 |
} |
538 |
} |
|
|
539 |
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 |
540 |
public void test322817() { |
541 |
Map customOptions = getCompilerOptions(); |
542 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); |
543 |
this.runNegativeTest( |
544 |
new String[] { |
545 |
"X.java", |
546 |
"interface Adaptable {\n" + |
547 |
" public Object getAdapter(Class clazz); \n" + |
548 |
"}\n" + |
549 |
"public class X implements Adaptable {\n" + |
550 |
" public Object getAdapter(Class clazz) {\n" + |
551 |
" return null;\n" + |
552 |
" }\n" + |
553 |
"}\n" |
554 |
}, |
555 |
"----------\n" + |
556 |
"1. WARNING in X.java (at line 2)\n" + |
557 |
" public Object getAdapter(Class clazz); \n" + |
558 |
" ^^^^^\n" + |
559 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
560 |
"----------\n", |
561 |
null, |
562 |
true, |
563 |
customOptions); |
564 |
} |
565 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 |
566 |
public void test322817b() { |
567 |
Map customOptions = getCompilerOptions(); |
568 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); |
569 |
this.runNegativeTest( |
570 |
new String[] { |
571 |
"X.java", |
572 |
"interface Adaptable {\n" + |
573 |
" public Object getAdapter(Class clazz); \n" + |
574 |
"}\n" + |
575 |
"public class X implements Adaptable {\n" + |
576 |
" public Object getAdapter(Class clazz) {\n" + |
577 |
" return null;\n" + |
578 |
" }\n" + |
579 |
"}\n" |
580 |
}, |
581 |
"----------\n" + |
582 |
"1. WARNING in X.java (at line 2)\n" + |
583 |
" public Object getAdapter(Class clazz); \n" + |
584 |
" ^^^^^\n" + |
585 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
586 |
"----------\n" + |
587 |
"2. WARNING in X.java (at line 5)\n" + |
588 |
" public Object getAdapter(Class clazz) {\n" + |
589 |
" ^^^^^\n" + |
590 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
591 |
"----------\n", |
592 |
null, |
593 |
true, |
594 |
customOptions); |
595 |
} |
596 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 |
597 |
public void test322817c() { |
598 |
Map customOptions = getCompilerOptions(); |
599 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); |
600 |
this.runNegativeTest( |
601 |
new String[] { |
602 |
"X.java", |
603 |
"interface Adaptable {\n" + |
604 |
" public Object getAdapter(Class<String> clazz); \n" + |
605 |
"}\n" + |
606 |
"public class X implements Adaptable {\n" + |
607 |
" public Object getAdapter(Class clazz) {\n" + |
608 |
" return null;\n" + |
609 |
" }\n" + |
610 |
"}\n" |
611 |
}, |
612 |
"----------\n" + |
613 |
"1. WARNING in X.java (at line 5)\n" + |
614 |
" public Object getAdapter(Class clazz) {\n" + |
615 |
" ^^^^^\n" + |
616 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
617 |
"----------\n", |
618 |
null, |
619 |
true, |
620 |
customOptions); |
621 |
} |
622 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 |
623 |
public void test322817d() { |
624 |
Map customOptions = getCompilerOptions(); |
625 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); |
626 |
this.runNegativeTest( |
627 |
new String[] { |
628 |
"X.java", |
629 |
"interface Adaptable {\n" + |
630 |
" public Object getAdapter(Class<String> clazz); \n" + |
631 |
"}\n" + |
632 |
"public class X implements Adaptable {\n" + |
633 |
" public Object getAdapter(Class clazz) {\n" + |
634 |
" return null;\n" + |
635 |
" }\n" + |
636 |
"}\n" + |
637 |
"class Y extends X {\n" + |
638 |
" @Override\n" + |
639 |
" public Object getAdapter(Class clazz) {\n" + |
640 |
" return null;\n" + |
641 |
" }\n" + |
642 |
"}\n" |
643 |
|
644 |
}, |
645 |
"----------\n" + |
646 |
"1. WARNING in X.java (at line 5)\n" + |
647 |
" public Object getAdapter(Class clazz) {\n" + |
648 |
" ^^^^^\n" + |
649 |
"Class is a raw type. References to generic type Class<T> should be parameterized\n" + |
650 |
"----------\n", |
651 |
null, |
652 |
true, |
653 |
customOptions); |
654 |
} |
655 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 |
656 |
public void test322817e() { |
657 |
Map customOptions = getCompilerOptions(); |
658 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); |
659 |
this.runNegativeTest( |
660 |
new String[] { |
661 |
"X.java", |
662 |
"import java.util.List;\n" + |
663 |
"class Top {\n" + |
664 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
665 |
" public List get() { return null; } // OK to warn in 1.5 code\n" + |
666 |
"}\n" + |
667 |
"class Sub extends Top {\n" + |
668 |
" @Override\n" + |
669 |
" public void set(List arg) { // should not warn (overrides)\n" + |
670 |
" }\n" + |
671 |
" @Override\n" + |
672 |
" public List get() { // should not warn (overrides)\n" + |
673 |
" return super.get();\n" + |
674 |
" }\n" + |
675 |
"}\n" + |
676 |
"public class X {\n" + |
677 |
"}\n" |
678 |
}, |
679 |
"----------\n" + |
680 |
"1. WARNING in X.java (at line 3)\n" + |
681 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
682 |
" ^^^^\n" + |
683 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
684 |
"----------\n" + |
685 |
"2. WARNING in X.java (at line 4)\n" + |
686 |
" public List get() { return null; } // OK to warn in 1.5 code\n" + |
687 |
" ^^^^\n" + |
688 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
689 |
"----------\n", |
690 |
null, |
691 |
true, |
692 |
customOptions); |
693 |
} |
694 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 |
695 |
public void test322817f() { |
696 |
Map customOptions = getCompilerOptions(); |
697 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); |
698 |
this.runNegativeTest( |
699 |
new String[] { |
700 |
"X.java", |
701 |
"import java.util.List;\n" + |
702 |
"class Top {\n" + |
703 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
704 |
" public List<String> get() { return null; }\n" + |
705 |
"}\n" + |
706 |
"class Sub extends Top {\n" + |
707 |
" @Override\n" + |
708 |
" public void set(List arg) { // should not warn (overrides)\n" + |
709 |
" }\n" + |
710 |
" @Override\n" + |
711 |
" public List get() { // should warn (super's return type is not raw)\n" + |
712 |
" return super.get();\n" + |
713 |
" }\n" + |
714 |
"}\n" + |
715 |
"public class X {\n" + |
716 |
"}\n" |
717 |
}, |
718 |
"----------\n" + |
719 |
"1. WARNING in X.java (at line 3)\n" + |
720 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
721 |
" ^^^^\n" + |
722 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
723 |
"----------\n" + |
724 |
"2. WARNING in X.java (at line 11)\n" + |
725 |
" public List get() { // should warn (super\'s return type is not raw)\n" + |
726 |
" ^^^^\n" + |
727 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
728 |
"----------\n" + |
729 |
"3. WARNING in X.java (at line 11)\n" + |
730 |
" public List get() { // should warn (super\'s return type is not raw)\n" + |
731 |
" ^^^^\n" + |
732 |
"Type safety: The return type List for get() from the type Sub needs unchecked conversion to conform to List<String> from the type Top\n" + |
733 |
"----------\n", |
734 |
null, |
735 |
true, |
736 |
customOptions); |
737 |
} |
738 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (Disable reporting of unavoidable problems) |
739 |
public void test322817g() { |
740 |
Map customOptions = getCompilerOptions(); |
741 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); |
742 |
this.runNegativeTest( |
743 |
new String[] { |
744 |
"Top.java", |
745 |
"import java.util.List;\n" + |
746 |
"public class Top {\n" + |
747 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
748 |
" public List get() { return null; } // OK to warn in 1.5 code\n" + |
749 |
" List list; // OK to warn in 1.5 code\n" + |
750 |
"}\n", |
751 |
"Sub.java", |
752 |
"import java.util.List;\n" + |
753 |
"public class Sub extends Top {\n" + |
754 |
" @Override\n" + |
755 |
" public void set(List arg) { // should not warn (overrides)\n" + |
756 |
" super.set(arg);\n" + |
757 |
" arg.set(0, \"A\"); // should not warn ('arg' is forced raw)\n" + |
758 |
" }\n" + |
759 |
" @Override\n" + |
760 |
" public List get() { // should not warn (overrides)\n" + |
761 |
" return super.get();\n" + |
762 |
" }\n" + |
763 |
"}\n", |
764 |
"X.java", |
765 |
"import java.util.List;\n" + |
766 |
"public class X {\n" + |
767 |
" void run() {\n" + |
768 |
" new Top().list.add(\"arg\"); // should not warn (uses raw field declared elsewhere)\n" + |
769 |
" new Top().get().add(\"arg\"); // should not warn (uses raw API)\n" + |
770 |
" List raw= new Top().get(); // OK to warn ('raw' declared here)\n" + |
771 |
" raw.add(\"arg\"); // OK to warn ('raw' declared here)\n" + |
772 |
" // When Top#get() is generified, both of the following will fail\n" + |
773 |
" // with a compile error if type arguments don't match:\n" + |
774 |
" List<String> unchecked= new Top().get(); // should not warn (forced)\n" + |
775 |
" unchecked.add(\"x\");\n" + |
776 |
" // Should not warn about unchecked cast, but should warn about\n" + |
777 |
" // unnecessary cast:\n" + |
778 |
" List<String> cast= (List<String>) new Top().get();\n" + |
779 |
" cast.add(\"x\");\n" + |
780 |
" }\n" + |
781 |
"}\n" |
782 |
}, |
783 |
"----------\n" + |
784 |
"1. WARNING in Top.java (at line 3)\n" + |
785 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
786 |
" ^^^^\n" + |
787 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
788 |
"----------\n" + |
789 |
"2. WARNING in Top.java (at line 4)\n" + |
790 |
" public List get() { return null; } // OK to warn in 1.5 code\n" + |
791 |
" ^^^^\n" + |
792 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
793 |
"----------\n" + |
794 |
"3. WARNING in Top.java (at line 5)\n" + |
795 |
" List list; // OK to warn in 1.5 code\n" + |
796 |
" ^^^^\n" + |
797 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
798 |
"----------\n" + |
799 |
"----------\n" + |
800 |
"1. WARNING in X.java (at line 6)\n" + |
801 |
" List raw= new Top().get(); // OK to warn (\'raw\' declared here)\n" + |
802 |
" ^^^^\n" + |
803 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
804 |
"----------\n" + |
805 |
"2. WARNING in X.java (at line 7)\n" + |
806 |
" raw.add(\"arg\"); // OK to warn (\'raw\' declared here)\n" + |
807 |
" ^^^^^^^^^^^^^^\n" + |
808 |
"Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + |
809 |
"----------\n" + |
810 |
"3. WARNING in X.java (at line 14)\n" + |
811 |
" List<String> cast= (List<String>) new Top().get();\n" + |
812 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
813 |
"Unnecessary cast from List to List<String>\n" + |
814 |
"----------\n", |
815 |
null, |
816 |
true, |
817 |
customOptions); |
818 |
} |
819 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (Enable reporting of unavoidable problems) |
820 |
public void test322817h() { |
821 |
Map customOptions = getCompilerOptions(); |
822 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); |
823 |
this.runNegativeTest( |
824 |
new String[] { |
825 |
"Top.java", |
826 |
"import java.util.List;\n" + |
827 |
"public class Top {\n" + |
828 |
" public void set(List arg) { }\n" + |
829 |
" public List get() { return null; }\n" + |
830 |
" List list;\n" + |
831 |
"}\n", |
832 |
"Sub.java", |
833 |
"import java.util.List;\n" + |
834 |
"public class Sub extends Top {\n" + |
835 |
" @Override\n" + |
836 |
" public void set(List arg) {\n" + |
837 |
" super.set(arg);\n" + |
838 |
" arg.set(0, \"A\");\n" + |
839 |
" }\n" + |
840 |
" @Override\n" + |
841 |
" public List get() {\n" + |
842 |
" return super.get();\n" + |
843 |
" }\n" + |
844 |
"}\n", |
845 |
"X.java", |
846 |
"import java.util.List;\n" + |
847 |
"public class X {\n" + |
848 |
" void run() {\n" + |
849 |
" new Top().list.add(\"arg\");\n" + |
850 |
" new Top().get().add(\"arg\");\n" + |
851 |
" List raw= new Top().get();\n" + |
852 |
" raw.add(\"arg\");\n" + |
853 |
" List<String> unchecked= new Top().get();\n" + |
854 |
" unchecked.add(\"x\");\n" + |
855 |
" List<String> cast= (List<String>) new Top().get();\n" + |
856 |
" cast.add(\"x\");\n" + |
857 |
" }\n" + |
858 |
"}\n" |
859 |
}, |
860 |
"----------\n" + |
861 |
"1. WARNING in Top.java (at line 3)\n" + |
862 |
" public void set(List arg) { }\n" + |
863 |
" ^^^^\n" + |
864 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
865 |
"----------\n" + |
866 |
"2. WARNING in Top.java (at line 4)\n" + |
867 |
" public List get() { return null; }\n" + |
868 |
" ^^^^\n" + |
869 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
870 |
"----------\n" + |
871 |
"3. WARNING in Top.java (at line 5)\n" + |
872 |
" List list;\n" + |
873 |
" ^^^^\n" + |
874 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
875 |
"----------\n" + |
876 |
"----------\n" + |
877 |
"1. WARNING in Sub.java (at line 4)\n" + |
878 |
" public void set(List arg) {\n" + |
879 |
" ^^^^\n" + |
880 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
881 |
"----------\n" + |
882 |
"2. WARNING in Sub.java (at line 6)\n" + |
883 |
" arg.set(0, \"A\");\n" + |
884 |
" ^^^^^^^^^^^^^^^\n" + |
885 |
"Type safety: The method set(int, Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + |
886 |
"----------\n" + |
887 |
"3. WARNING in Sub.java (at line 9)\n" + |
888 |
" public List get() {\n" + |
889 |
" ^^^^\n" + |
890 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
891 |
"----------\n" + |
892 |
"----------\n" + |
893 |
"1. WARNING in X.java (at line 4)\n" + |
894 |
" new Top().list.add(\"arg\");\n" + |
895 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
896 |
"Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + |
897 |
"----------\n" + |
898 |
"2. WARNING in X.java (at line 5)\n" + |
899 |
" new Top().get().add(\"arg\");\n" + |
900 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
901 |
"Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + |
902 |
"----------\n" + |
903 |
"3. WARNING in X.java (at line 6)\n" + |
904 |
" List raw= new Top().get();\n" + |
905 |
" ^^^^\n" + |
906 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
907 |
"----------\n" + |
908 |
"4. WARNING in X.java (at line 7)\n" + |
909 |
" raw.add(\"arg\");\n" + |
910 |
" ^^^^^^^^^^^^^^\n" + |
911 |
"Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + |
912 |
"----------\n" + |
913 |
"5. WARNING in X.java (at line 8)\n" + |
914 |
" List<String> unchecked= new Top().get();\n" + |
915 |
" ^^^^^^^^^^^^^^^\n" + |
916 |
"Type safety: The expression of type List needs unchecked conversion to conform to List<String>\n" + |
917 |
"----------\n" + |
918 |
"6. WARNING in X.java (at line 10)\n" + |
919 |
" List<String> cast= (List<String>) new Top().get();\n" + |
920 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
921 |
"Type safety: Unchecked cast from List to List<String>\n" + |
922 |
"----------\n" + |
923 |
"7. WARNING in X.java (at line 10)\n" + |
924 |
" List<String> cast= (List<String>) new Top().get();\n" + |
925 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
926 |
"Unnecessary cast from List to List<String>\n" + |
927 |
"----------\n", |
928 |
null, |
929 |
true, |
930 |
customOptions); |
931 |
} |
932 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (Default options) |
933 |
public void test322817i() { |
934 |
Map customOptions = getCompilerOptions(); |
935 |
this.runNegativeTest( |
936 |
new String[] { |
937 |
"Top.java", |
938 |
"import java.util.List;\n" + |
939 |
"public class Top {\n" + |
940 |
" public void set(List arg) { }\n" + |
941 |
" public List get() { return null; }\n" + |
942 |
" List list;\n" + |
943 |
"}\n", |
944 |
"Sub.java", |
945 |
"import java.util.List;\n" + |
946 |
"public class Sub extends Top {\n" + |
947 |
" @Override\n" + |
948 |
" public void set(List arg) {\n" + |
949 |
" super.set(arg);\n" + |
950 |
" arg.set(0, \"A\");\n" + |
951 |
" }\n" + |
952 |
" @Override\n" + |
953 |
" public List get() {\n" + |
954 |
" return super.get();\n" + |
955 |
" }\n" + |
956 |
"}\n", |
957 |
"X.java", |
958 |
"import java.util.List;\n" + |
959 |
"public class X {\n" + |
960 |
" void run() {\n" + |
961 |
" new Top().list.add(\"arg\");\n" + |
962 |
" new Top().get().add(\"arg\");\n" + |
963 |
" List raw= new Top().get();\n" + |
964 |
" raw.add(\"arg\");\n" + |
965 |
" List<String> unchecked= new Top().get();\n" + |
966 |
" unchecked.add(\"x\");\n" + |
967 |
" List<String> cast= (List<String>) new Top().get();\n" + |
968 |
" cast.add(\"x\");\n" + |
969 |
" }\n" + |
970 |
"}\n" |
971 |
}, |
972 |
"----------\n" + |
973 |
"1. WARNING in Top.java (at line 3)\n" + |
974 |
" public void set(List arg) { }\n" + |
975 |
" ^^^^\n" + |
976 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
977 |
"----------\n" + |
978 |
"2. WARNING in Top.java (at line 4)\n" + |
979 |
" public List get() { return null; }\n" + |
980 |
" ^^^^\n" + |
981 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
982 |
"----------\n" + |
983 |
"3. WARNING in Top.java (at line 5)\n" + |
984 |
" List list;\n" + |
985 |
" ^^^^\n" + |
986 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
987 |
"----------\n" + |
988 |
"----------\n" + |
989 |
"1. WARNING in Sub.java (at line 4)\n" + |
990 |
" public void set(List arg) {\n" + |
991 |
" ^^^^\n" + |
992 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
993 |
"----------\n" + |
994 |
"2. WARNING in Sub.java (at line 6)\n" + |
995 |
" arg.set(0, \"A\");\n" + |
996 |
" ^^^^^^^^^^^^^^^\n" + |
997 |
"Type safety: The method set(int, Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + |
998 |
"----------\n" + |
999 |
"3. WARNING in Sub.java (at line 9)\n" + |
1000 |
" public List get() {\n" + |
1001 |
" ^^^^\n" + |
1002 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
1003 |
"----------\n" + |
1004 |
"----------\n" + |
1005 |
"1. WARNING in X.java (at line 4)\n" + |
1006 |
" new Top().list.add(\"arg\");\n" + |
1007 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
1008 |
"Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + |
1009 |
"----------\n" + |
1010 |
"2. WARNING in X.java (at line 5)\n" + |
1011 |
" new Top().get().add(\"arg\");\n" + |
1012 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
1013 |
"Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + |
1014 |
"----------\n" + |
1015 |
"3. WARNING in X.java (at line 6)\n" + |
1016 |
" List raw= new Top().get();\n" + |
1017 |
" ^^^^\n" + |
1018 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
1019 |
"----------\n" + |
1020 |
"4. WARNING in X.java (at line 7)\n" + |
1021 |
" raw.add(\"arg\");\n" + |
1022 |
" ^^^^^^^^^^^^^^\n" + |
1023 |
"Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + |
1024 |
"----------\n" + |
1025 |
"5. WARNING in X.java (at line 8)\n" + |
1026 |
" List<String> unchecked= new Top().get();\n" + |
1027 |
" ^^^^^^^^^^^^^^^\n" + |
1028 |
"Type safety: The expression of type List needs unchecked conversion to conform to List<String>\n" + |
1029 |
"----------\n" + |
1030 |
"6. WARNING in X.java (at line 10)\n" + |
1031 |
" List<String> cast= (List<String>) new Top().get();\n" + |
1032 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
1033 |
"Type safety: Unchecked cast from List to List<String>\n" + |
1034 |
"----------\n" + |
1035 |
"7. WARNING in X.java (at line 10)\n" + |
1036 |
" List<String> cast= (List<String>) new Top().get();\n" + |
1037 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
1038 |
"Unnecessary cast from List to List<String>\n" + |
1039 |
"----------\n", |
1040 |
null, |
1041 |
true, |
1042 |
customOptions); |
1043 |
} |
1044 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (all in same file) |
1045 |
public void test322817j() { |
1046 |
Map customOptions = getCompilerOptions(); |
1047 |
customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); |
1048 |
this.runNegativeTest( |
1049 |
new String[] { |
1050 |
"X.java", |
1051 |
"import java.util.List;\n" + |
1052 |
"class Top {\n" + |
1053 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
1054 |
" public List get() { return null; } // OK to warn in 1.5 code\n" + |
1055 |
"}\n" + |
1056 |
"class Sub extends Top {\n" + |
1057 |
" @Override\n" + |
1058 |
" public void set(List arg) { // should not warn (overrides)\n" + |
1059 |
" super.set(arg);\n" + |
1060 |
" arg.set(0, \"A\"); // should not warn ('arg' is forced raw)\n" + |
1061 |
" }\n" + |
1062 |
" @Override\n" + |
1063 |
" public List get() { // should not warn (overrides)\n" + |
1064 |
" return super.get();\n" + |
1065 |
" }\n" + |
1066 |
"}\n" + |
1067 |
"public class X {\n" + |
1068 |
" void run() {\n" + |
1069 |
" new Top().get().add(\"arg\");\n" + |
1070 |
" List raw= new Top().get(); // OK to warn ('raw' declared here)\n" + |
1071 |
" raw.add(\"arg\"); // OK to warn ('raw' declared here)\n" + |
1072 |
" List<String> unchecked= new Top().get();\n" + |
1073 |
" unchecked.add(\"x\");\n" + |
1074 |
" List<String> cast= (List<String>) new Top().get();\n" + |
1075 |
" cast.add(\"x\");\n" + |
1076 |
" }\n" + |
1077 |
"}\n" |
1078 |
}, |
1079 |
"----------\n" + |
1080 |
"1. WARNING in X.java (at line 3)\n" + |
1081 |
" public void set(List arg) { } // OK to warn in 1.5 code\n" + |
1082 |
" ^^^^\n" + |
1083 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
1084 |
"----------\n" + |
1085 |
"2. WARNING in X.java (at line 4)\n" + |
1086 |
" public List get() { return null; } // OK to warn in 1.5 code\n" + |
1087 |
" ^^^^\n" + |
1088 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
1089 |
"----------\n" + |
1090 |
"3. WARNING in X.java (at line 19)\n" + |
1091 |
" new Top().get().add(\"arg\");\n" + |
1092 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
1093 |
"Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + |
1094 |
"----------\n" + |
1095 |
"4. WARNING in X.java (at line 20)\n" + |
1096 |
" List raw= new Top().get(); // OK to warn (\'raw\' declared here)\n" + |
1097 |
" ^^^^\n" + |
1098 |
"List is a raw type. References to generic type List<E> should be parameterized\n" + |
1099 |
"----------\n" + |
1100 |
"5. WARNING in X.java (at line 21)\n" + |
1101 |
" raw.add(\"arg\"); // OK to warn (\'raw\' declared here)\n" + |
1102 |
" ^^^^^^^^^^^^^^\n" + |
1103 |
"Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" + |
1104 |
"----------\n" + |
1105 |
"6. WARNING in X.java (at line 22)\n" + |
1106 |
" List<String> unchecked= new Top().get();\n" + |
1107 |
" ^^^^^^^^^^^^^^^\n" + |
1108 |
"Type safety: The expression of type List needs unchecked conversion to conform to List<String>\n" + |
1109 |
"----------\n" + |
1110 |
"7. WARNING in X.java (at line 24)\n" + |
1111 |
" List<String> cast= (List<String>) new Top().get();\n" + |
1112 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
1113 |
"Type safety: Unchecked cast from List to List<String>\n" + |
1114 |
"----------\n" + |
1115 |
"8. WARNING in X.java (at line 24)\n" + |
1116 |
" List<String> cast= (List<String>) new Top().get();\n" + |
1117 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
1118 |
"Unnecessary cast from List to List<String>\n" + |
1119 |
"----------\n", |
1120 |
null, |
1121 |
true, |
1122 |
customOptions); |
1123 |
} |
1124 |
|
539 |
} |
1125 |
} |