|
Lines 53-59
Link Here
|
| 53 |
// Static initializer to specify tests subset using TESTS_* static variables |
53 |
// Static initializer to specify tests subset using TESTS_* static variables |
| 54 |
// All specified tests which do not belong to the class are skipped... |
54 |
// All specified tests which do not belong to the class are skipped... |
| 55 |
static { |
55 |
static { |
| 56 |
// TESTS_NAMES = new String[] { "testBug385626" }; |
56 |
// TESTS_NAMES = new String[] { "testBug388281_08" }; |
| 57 |
// TESTS_NUMBERS = new int[] { 561 }; |
57 |
// TESTS_NUMBERS = new int[] { 561 }; |
| 58 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
58 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
| 59 |
} |
59 |
} |
|
Lines 3715-3718
Link Here
|
| 3715 |
null,//options |
3715 |
null,//options |
| 3716 |
""); |
3716 |
""); |
| 3717 |
} |
3717 |
} |
|
|
3718 |
|
| 3719 |
/* Content of Test388281.jar used in the following tests: |
| 3720 |
|
| 3721 |
// === package i (explicit annotations): === |
| 3722 |
package i; |
| 3723 |
import org.eclipse.jdt.annotation.NonNull; |
| 3724 |
import org.eclipse.jdt.annotation.Nullable; |
| 3725 |
public interface I { |
| 3726 |
@NonNull Object m1(@Nullable Object a1); |
| 3727 |
@Nullable String m2(@NonNull Object a2); |
| 3728 |
Object m1(@Nullable Object o1, Object o2); |
| 3729 |
} |
| 3730 |
|
| 3731 |
// === package i2 with package-info.java (default annot, canceled in one type): === |
| 3732 |
@org.eclipse.jdt.annotation.NonNullByDefault |
| 3733 |
package i2; |
| 3734 |
|
| 3735 |
package i2; |
| 3736 |
public interface I2 { |
| 3737 |
Object m1(Object a1); |
| 3738 |
String m2(Object a2); |
| 3739 |
} |
| 3740 |
|
| 3741 |
package i2; |
| 3742 |
public interface II extends i.I { |
| 3743 |
String m1(Object o1, Object o2); |
| 3744 |
} |
| 3745 |
|
| 3746 |
package i2; |
| 3747 |
import org.eclipse.jdt.annotation.NonNullByDefault; |
| 3748 |
@NonNullByDefault(false) |
| 3749 |
public interface I2A { |
| 3750 |
Object m1(Object a1); |
| 3751 |
String m2(Object a2); |
| 3752 |
} |
| 3753 |
|
| 3754 |
// === package c (no null annotations): === |
| 3755 |
package c; |
| 3756 |
public class C1 implements i.I { |
| 3757 |
public Object m1(Object a1) { |
| 3758 |
System.out.println(a1.toString()); // (1) |
| 3759 |
return null; // (2) |
| 3760 |
} |
| 3761 |
public String m2(Object a2) { |
| 3762 |
System.out.println(a2.toString()); |
| 3763 |
return null; |
| 3764 |
} |
| 3765 |
public Object m1(Object o1, Object o2) { |
| 3766 |
return null; |
| 3767 |
} |
| 3768 |
} |
| 3769 |
|
| 3770 |
package c; |
| 3771 |
public class C2 implements i2.I2 { |
| 3772 |
public Object m1(Object a1) { |
| 3773 |
return a1; |
| 3774 |
} |
| 3775 |
public String m2(Object a2) { |
| 3776 |
return a2.toString(); |
| 3777 |
} |
| 3778 |
} |
| 3779 |
*/ |
| 3780 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 |
| 3781 |
// Test whether null annotations from a super interface are respected |
| 3782 |
// Class and its super interface both read from binary |
| 3783 |
public void testBug388281_01() { |
| 3784 |
String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test388281.jar"; |
| 3785 |
String[] libs = new String[this.LIBS.length + 1]; |
| 3786 |
System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); |
| 3787 |
libs[this.LIBS.length] = path; |
| 3788 |
Map options = getCompilerOptions(); |
| 3789 |
options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); |
| 3790 |
runNegativeTest( |
| 3791 |
new String[] { |
| 3792 |
"Client.java", |
| 3793 |
"import c.C1;\n" + |
| 3794 |
"public class Client {\n" + |
| 3795 |
" void test(C1 c) {\n" + |
| 3796 |
" String s = c.m2(null); // (3)\n" + |
| 3797 |
" System.out.println(s.toUpperCase()); // (4)\n" + |
| 3798 |
" }\n" + |
| 3799 |
"}\n" |
| 3800 |
}, |
| 3801 |
"----------\n" + |
| 3802 |
"1. ERROR in Client.java (at line 4)\n" + |
| 3803 |
" String s = c.m2(null); // (3)\n" + |
| 3804 |
" ^^^^\n" + |
| 3805 |
"Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + |
| 3806 |
"----------\n" + |
| 3807 |
"2. ERROR in Client.java (at line 5)\n" + |
| 3808 |
" System.out.println(s.toUpperCase()); // (4)\n" + |
| 3809 |
" ^\n" + |
| 3810 |
"Potential null pointer access: The variable s may be null at this location\n" + |
| 3811 |
"----------\n", |
| 3812 |
libs, |
| 3813 |
true /* shouldFlush*/, |
| 3814 |
options); |
| 3815 |
} |
| 3816 |
|
| 3817 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 |
| 3818 |
// Test whether null annotations from a super interface are respected |
| 3819 |
// Class from source, its supers (class + super interface) from binary |
| 3820 |
public void testBug388281_02() { |
| 3821 |
String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test388281.jar"; |
| 3822 |
String[] libs = new String[this.LIBS.length + 1]; |
| 3823 |
System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); |
| 3824 |
libs[this.LIBS.length] = path; |
| 3825 |
Map options = getCompilerOptions(); |
| 3826 |
options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); |
| 3827 |
runNegativeTest( |
| 3828 |
new String[] { |
| 3829 |
"ctest/C.java", |
| 3830 |
"package ctest;\n" + |
| 3831 |
"public class C extends c.C1 {\n" + |
| 3832 |
" @Override\n" + |
| 3833 |
" public Object m1(Object a1) {\n" + |
| 3834 |
" System.out.println(a1.toString()); // (1)\n" + |
| 3835 |
" return null; // (2)\n" + |
| 3836 |
" }\n" + |
| 3837 |
" @Override\n" + |
| 3838 |
" public String m2(Object a2) {\n" + |
| 3839 |
" System.out.println(a2.toString());\n" + |
| 3840 |
" return null;\n" + |
| 3841 |
" }\n" + |
| 3842 |
"}\n", |
| 3843 |
"Client.java", |
| 3844 |
"import ctest.C;\n" + |
| 3845 |
"public class Client {\n" + |
| 3846 |
" void test(C c) {\n" + |
| 3847 |
" String s = c.m2(null); // (3)\n" + |
| 3848 |
" System.out.println(s.toUpperCase()); // (4)\n" + |
| 3849 |
" }\n" + |
| 3850 |
"}\n" |
| 3851 |
}, |
| 3852 |
"----------\n" + |
| 3853 |
"1. ERROR in ctest\\C.java (at line 5)\n" + |
| 3854 |
" System.out.println(a1.toString()); // (1)\n" + |
| 3855 |
" ^^\n" + |
| 3856 |
"Potential null pointer access: The variable a1 may be null at this location\n" + |
| 3857 |
"----------\n" + |
| 3858 |
"2. ERROR in ctest\\C.java (at line 6)\n" + |
| 3859 |
" return null; // (2)\n" + |
| 3860 |
" ^^^^\n" + |
| 3861 |
"Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + |
| 3862 |
"----------\n" + |
| 3863 |
"----------\n" + |
| 3864 |
"1. ERROR in Client.java (at line 4)\n" + |
| 3865 |
" String s = c.m2(null); // (3)\n" + |
| 3866 |
" ^^^^\n" + |
| 3867 |
"Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + |
| 3868 |
"----------\n" + |
| 3869 |
"2. ERROR in Client.java (at line 5)\n" + |
| 3870 |
" System.out.println(s.toUpperCase()); // (4)\n" + |
| 3871 |
" ^\n" + |
| 3872 |
"Potential null pointer access: The variable s may be null at this location\n" + |
| 3873 |
"----------\n", |
| 3874 |
libs, |
| 3875 |
true /* shouldFlush*/, |
| 3876 |
options); |
| 3877 |
} |
| 3878 |
|
| 3879 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 |
| 3880 |
// Test whether null annotations from a super interface trigger an error against the overriding implementation |
| 3881 |
// Class from source, its super interface from binary |
| 3882 |
public void testBug388281_03() { |
| 3883 |
String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test388281.jar"; |
| 3884 |
String[] libs = new String[this.LIBS.length + 1]; |
| 3885 |
System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); |
| 3886 |
libs[this.LIBS.length] = path; |
| 3887 |
Map options = getCompilerOptions(); |
| 3888 |
options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); |
| 3889 |
runNegativeTest( |
| 3890 |
new String[] { |
| 3891 |
"ctest/C.java", |
| 3892 |
"package ctest;\n" + |
| 3893 |
"public class C implements i.I {\n" + |
| 3894 |
" public Object m1(Object a1) {\n" + |
| 3895 |
" System.out.println(a1.toString()); // (1)\n" + |
| 3896 |
" return null; // (2)\n" + |
| 3897 |
" }\n" + |
| 3898 |
" public String m2(Object a2) {\n" + |
| 3899 |
" System.out.println(a2.toString());\n" + |
| 3900 |
" return null;\n" + |
| 3901 |
" }\n" + |
| 3902 |
" public Object m1(Object a1, Object a2) {\n" + |
| 3903 |
" System.out.println(a1.toString()); // (3)\n" + |
| 3904 |
" return null;\n" + |
| 3905 |
" }\n" + |
| 3906 |
"}\n" |
| 3907 |
}, |
| 3908 |
"----------\n" + |
| 3909 |
"1. ERROR in ctest\\C.java (at line 4)\n" + |
| 3910 |
" System.out.println(a1.toString()); // (1)\n" + |
| 3911 |
" ^^\n" + |
| 3912 |
"Potential null pointer access: The variable a1 may be null at this location\n" + |
| 3913 |
"----------\n" + |
| 3914 |
"2. ERROR in ctest\\C.java (at line 5)\n" + |
| 3915 |
" return null; // (2)\n" + |
| 3916 |
" ^^^^\n" + |
| 3917 |
"Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + |
| 3918 |
"----------\n" + |
| 3919 |
"3. ERROR in ctest\\C.java (at line 12)\n" + |
| 3920 |
" System.out.println(a1.toString()); // (3)\n" + |
| 3921 |
" ^^\n" + |
| 3922 |
"Potential null pointer access: The variable a1 may be null at this location\n" + |
| 3923 |
"----------\n", |
| 3924 |
libs, |
| 3925 |
true /* shouldFlush*/, |
| 3926 |
options); |
| 3927 |
} |
| 3928 |
|
| 3929 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 |
| 3930 |
// Do inherit even if one parameter/return is annotated |
| 3931 |
// also features some basic overloading |
| 3932 |
public void testBug388281_04() { |
| 3933 |
Map options = getCompilerOptions(); |
| 3934 |
options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); |
| 3935 |
runNegativeTestWithLibs( |
| 3936 |
true /* shouldFlush*/, |
| 3937 |
new String[] { |
| 3938 |
"i/I.java", |
| 3939 |
"package i;\n" + |
| 3940 |
"import org.eclipse.jdt.annotation.*;\n" + |
| 3941 |
"public interface I {\n" + |
| 3942 |
" @NonNull Object m1(@NonNull Object s1, @Nullable String s2);\n" + |
| 3943 |
" @Nullable Object m1(@Nullable String s1, @NonNull Object s2);\n" + |
| 3944 |
"}\n", |
| 3945 |
"ctest/C.java", |
| 3946 |
"package ctest;\n" + |
| 3947 |
"import org.eclipse.jdt.annotation.*;\n" + |
| 3948 |
"public class C implements i.I {\n" + |
| 3949 |
" public Object m1(@Nullable Object o1, String s2) {\n" + |
| 3950 |
" System.out.println(s2.toString()); // (1)\n" + |
| 3951 |
" return null; // (2)\n" + |
| 3952 |
" }\n" + |
| 3953 |
" public @NonNull Object m1(String s1, Object o2) {\n" + |
| 3954 |
" System.out.println(s1.toString()); // (3)\n" + |
| 3955 |
" return new Object();\n" + |
| 3956 |
" }\n" + |
| 3957 |
"}\n" |
| 3958 |
}, |
| 3959 |
options, |
| 3960 |
"----------\n" + |
| 3961 |
"1. ERROR in ctest\\C.java (at line 5)\n" + |
| 3962 |
" System.out.println(s2.toString()); // (1)\n" + |
| 3963 |
" ^^\n" + |
| 3964 |
"Potential null pointer access: The variable s2 may be null at this location\n" + |
| 3965 |
"----------\n" + |
| 3966 |
"2. ERROR in ctest\\C.java (at line 6)\n" + |
| 3967 |
" return null; // (2)\n" + |
| 3968 |
" ^^^^\n" + |
| 3969 |
"Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + |
| 3970 |
"----------\n" + |
| 3971 |
"3. ERROR in ctest\\C.java (at line 9)\n" + |
| 3972 |
" System.out.println(s1.toString()); // (3)\n" + |
| 3973 |
" ^^\n" + |
| 3974 |
"Potential null pointer access: The variable s1 may be null at this location\n" + |
| 3975 |
"----------\n"); |
| 3976 |
} |
| 3977 |
|
| 3978 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 |
| 3979 |
// Test whether null annotations from a super interface trigger an error against the overriding implementation |
| 3980 |
// Class from source, its super interface from binary |
| 3981 |
// Super interface subject to package level @NonNullByDefault |
| 3982 |
public void testBug388281_05() { |
| 3983 |
String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test388281.jar"; |
| 3984 |
String[] libs = new String[this.LIBS.length + 1]; |
| 3985 |
System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); |
| 3986 |
libs[this.LIBS.length] = path; |
| 3987 |
Map options = getCompilerOptions(); |
| 3988 |
options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); |
| 3989 |
runNegativeTest( |
| 3990 |
new String[] { |
| 3991 |
"ctest/C.java", |
| 3992 |
"package ctest;\n" + |
| 3993 |
"public class C implements i2.I2 {\n" + |
| 3994 |
" public Object m1(Object a1) {\n" + |
| 3995 |
" System.out.println(a1.toString()); // silent\n" + |
| 3996 |
" return null; // (1)\n" + |
| 3997 |
" }\n" + |
| 3998 |
" public String m2(Object a2) {\n" + |
| 3999 |
" System.out.println(a2.toString());\n" + |
| 4000 |
" return null; // (2)\n" + |
| 4001 |
" }\n" + |
| 4002 |
"}\n", |
| 4003 |
"Client.java", |
| 4004 |
"import ctest.C;\n" + |
| 4005 |
"public class Client {\n" + |
| 4006 |
" void test(C c) {\n" + |
| 4007 |
" String s = c.m2(null); // (3)\n" + |
| 4008 |
" }\n" + |
| 4009 |
"}\n" |
| 4010 |
}, |
| 4011 |
"----------\n" + |
| 4012 |
"1. ERROR in ctest\\C.java (at line 5)\n" + |
| 4013 |
" return null; // (1)\n" + |
| 4014 |
" ^^^^\n" + |
| 4015 |
"Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + |
| 4016 |
"----------\n" + |
| 4017 |
"2. ERROR in ctest\\C.java (at line 9)\n" + |
| 4018 |
" return null; // (2)\n" + |
| 4019 |
" ^^^^\n" + |
| 4020 |
"Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + |
| 4021 |
"----------\n" + |
| 4022 |
"----------\n" + |
| 4023 |
"1. ERROR in Client.java (at line 4)\n" + |
| 4024 |
" String s = c.m2(null); // (3)\n" + |
| 4025 |
" ^^^^\n" + |
| 4026 |
"Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + |
| 4027 |
"----------\n", |
| 4028 |
libs, |
| 4029 |
true /* shouldFlush*/, |
| 4030 |
options); |
| 4031 |
} |
| 4032 |
|
| 4033 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 |
| 4034 |
// Conflicting annotations from several indirect super interfaces must be detected |
| 4035 |
public void testBug388281_06() { |
| 4036 |
String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test388281.jar"; |
| 4037 |
String[] libs = new String[this.LIBS.length + 1]; |
| 4038 |
System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); |
| 4039 |
libs[this.LIBS.length] = path; |
| 4040 |
Map options = getCompilerOptions(); |
| 4041 |
options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); |
| 4042 |
runNegativeTest( |
| 4043 |
new String[] { |
| 4044 |
"ctest/C.java", |
| 4045 |
"package ctest;\n" + |
| 4046 |
"public class C extends c.C2 implements i2.I2A {\n" + // neither super has explicit annotations, |
| 4047 |
// but C2 inherits those from the default applicable at its super interface i2.I2 |
| 4048 |
// whereas I2A cancels that same default |
| 4049 |
"}\n" |
| 4050 |
}, |
| 4051 |
"----------\n" + |
| 4052 |
"1. ERROR in ctest\\C.java (at line 2)\n" + |
| 4053 |
" public class C extends c.C2 implements i2.I2A {\n" + |
| 4054 |
" ^\n" + |
| 4055 |
"The method m2(Object) from C2 cannot implement the corresponding method from I2A due to incompatible nullness constraints\n" + |
| 4056 |
"----------\n" + |
| 4057 |
"2. ERROR in ctest\\C.java (at line 2)\n" + |
| 4058 |
" public class C extends c.C2 implements i2.I2A {\n" + |
| 4059 |
" ^\n" + |
| 4060 |
"The method m1(Object) from C2 cannot implement the corresponding method from I2A due to incompatible nullness constraints\n" + |
| 4061 |
"----------\n", |
| 4062 |
libs, |
| 4063 |
true /* shouldFlush*/, |
| 4064 |
options); |
| 4065 |
} |
| 4066 |
|
| 4067 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 |
| 4068 |
// report conflict between inheritance and default |
| 4069 |
public void testBug388281_07() { |
| 4070 |
Map options = getCompilerOptions(); |
| 4071 |
options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); |
| 4072 |
runNegativeTestWithLibs( |
| 4073 |
new String[] { |
| 4074 |
"p1/Super.java", |
| 4075 |
"package p1;\n" + |
| 4076 |
"import org.eclipse.jdt.annotation.*;\n" + |
| 4077 |
"public class Super {\n" + |
| 4078 |
" public @Nullable Object m(@Nullable Object arg) {\n" + |
| 4079 |
" return null;" + |
| 4080 |
" }\n" + |
| 4081 |
"}\n", |
| 4082 |
"p2/Sub.java", |
| 4083 |
"package p2;\n" + |
| 4084 |
"import org.eclipse.jdt.annotation.*;\n" + |
| 4085 |
"@NonNullByDefault\n" + |
| 4086 |
"public class Sub extends p1.Super {\n" + |
| 4087 |
" @Override\n" + |
| 4088 |
" public Object m(Object arg) { // (a)+(b) conflict at arg and return\n" + |
| 4089 |
" System.out.println(arg.toString()); // (1)\n" + |
| 4090 |
" return null;\n" + |
| 4091 |
" }\n" + |
| 4092 |
"}\n", |
| 4093 |
"Client.java", |
| 4094 |
"public class Client {\n" + |
| 4095 |
" void test(p2.Sub s) {\n" + |
| 4096 |
" Object result = s.m(null);\n" + |
| 4097 |
" System.out.println(result.toString()); // (2)\n" + |
| 4098 |
" }\n" + |
| 4099 |
"}\n" |
| 4100 |
}, |
| 4101 |
options, |
| 4102 |
"----------\n" + |
| 4103 |
"1. ERROR in p2\\Sub.java (at line 6)\n" + |
| 4104 |
" public Object m(Object arg) { // (a)+(b) conflict at arg and return\n" + |
| 4105 |
" ^^^^^^\n" + |
| 4106 |
"The default \'@NonNull\' conflicts with the inherited \'@Nullable\' annotation in the overridden method from Super \n" + |
| 4107 |
"----------\n" + |
| 4108 |
"2. ERROR in p2\\Sub.java (at line 6)\n" + |
| 4109 |
" public Object m(Object arg) { // (a)+(b) conflict at arg and return\n" + |
| 4110 |
" ^^^\n" + |
| 4111 |
"The default \'@NonNull\' conflicts with the inherited \'@Nullable\' annotation in the overridden method from Super \n" + |
| 4112 |
"----------\n" + |
| 4113 |
"3. ERROR in p2\\Sub.java (at line 7)\n" + |
| 4114 |
" System.out.println(arg.toString()); // (1)\n" + |
| 4115 |
" ^^^\n" + |
| 4116 |
"Potential null pointer access: The variable arg may be null at this location\n" + |
| 4117 |
"----------\n" + |
| 4118 |
"----------\n" + |
| 4119 |
"1. ERROR in Client.java (at line 4)\n" + |
| 4120 |
" System.out.println(result.toString()); // (2)\n" + |
| 4121 |
" ^^^^^^\n" + |
| 4122 |
"Potential null pointer access: The variable result may be null at this location\n" + |
| 4123 |
"----------\n"); |
| 4124 |
} |
| 4125 |
|
| 4126 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 |
| 4127 |
// report conflict between inheritance and default - binary types |
| 4128 |
public void testBug388281_08() { |
| 4129 |
String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test388281.jar"; |
| 4130 |
String[] libs = new String[this.LIBS.length + 1]; |
| 4131 |
System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); |
| 4132 |
libs[this.LIBS.length] = path; |
| 4133 |
Map options = getCompilerOptions(); |
| 4134 |
options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); |
| 4135 |
runNegativeTest( |
| 4136 |
new String[] { |
| 4137 |
"ctest/Ctest.java", |
| 4138 |
"package ctest;\n" + |
| 4139 |
"import org.eclipse.jdt.annotation.*;\n" + |
| 4140 |
"@NonNullByDefault\n" + |
| 4141 |
"public class Ctest implements i2.II {\n" + |
| 4142 |
" public Object m1(@Nullable Object a1) { // silent: conflict at a1 avoided\n" + |
| 4143 |
" return new Object();\n" + |
| 4144 |
" }\n" + |
| 4145 |
" public String m2(Object a2) { // (a) conflict at return\n" + |
| 4146 |
" return null;\n" + |
| 4147 |
" }\n" + |
| 4148 |
" public String m1(Object o1, Object o2) { // (b) conflict at o1\n" + |
| 4149 |
" System.out.println(o1.toString()); // (1) inherited @Nullable\n" + |
| 4150 |
" return null; // (2) @NonNullByDefault in i2.II\n" + |
| 4151 |
" }\n" + |
| 4152 |
"}\n", |
| 4153 |
"Client.java", |
| 4154 |
"public class Client {\n" + |
| 4155 |
" void test(ctest.Ctest c) {\n" + |
| 4156 |
" Object result = c.m1(null, null); // (3) 2nd arg @NonNullByDefault from i2.II\n" + |
| 4157 |
" }\n" + |
| 4158 |
"}\n" |
| 4159 |
}, |
| 4160 |
"----------\n" + |
| 4161 |
"1. ERROR in ctest\\Ctest.java (at line 8)\n" + |
| 4162 |
" public String m2(Object a2) { // (a) conflict at return\n" + |
| 4163 |
" ^^^^^^\n" + |
| 4164 |
"The default \'@NonNull\' conflicts with the inherited \'@Nullable\' annotation in the overridden method from I \n" + |
| 4165 |
"----------\n" + |
| 4166 |
"2. ERROR in ctest\\Ctest.java (at line 11)\n" + |
| 4167 |
" public String m1(Object o1, Object o2) { // (b) conflict at o1\n" + |
| 4168 |
" ^^\n" + |
| 4169 |
"The default \'@NonNull\' conflicts with the inherited \'@Nullable\' annotation in the overridden method from II \n" + |
| 4170 |
"----------\n" + |
| 4171 |
"3. ERROR in ctest\\Ctest.java (at line 12)\n" + |
| 4172 |
" System.out.println(o1.toString()); // (1) inherited @Nullable\n" + |
| 4173 |
" ^^\n" + |
| 4174 |
"Potential null pointer access: The variable o1 may be null at this location\n" + |
| 4175 |
"----------\n" + |
| 4176 |
"4. ERROR in ctest\\Ctest.java (at line 13)\n" + |
| 4177 |
" return null; // (2) @NonNullByDefault in i2.II\n" + |
| 4178 |
" ^^^^\n" + |
| 4179 |
"Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + |
| 4180 |
"----------\n" + |
| 4181 |
"----------\n" + |
| 4182 |
"1. ERROR in Client.java (at line 3)\n" + |
| 4183 |
" Object result = c.m1(null, null); // (3) 2nd arg @NonNullByDefault from i2.II\n" + |
| 4184 |
" ^^^^\n" + |
| 4185 |
"Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + |
| 4186 |
"----------\n", |
| 4187 |
libs, |
| 4188 |
true, // should flush |
| 4189 |
options); |
| 4190 |
} |
| 3718 |
} |
4191 |
} |