Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2005, 2006 IBM Corporation and others. |
2 |
* Copyright (c) 2005, 2007 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 33-39
Link Here
|
33 |
// TESTS_RANGE = new int[] { 2050, -1 }; |
33 |
// TESTS_RANGE = new int[] { 2050, -1 }; |
34 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
34 |
// TESTS_RANGE = new int[] { 1, 2049 }; |
35 |
// TESTS_RANGE = new int[] { 449, 451 }; |
35 |
// TESTS_RANGE = new int[] { 449, 451 }; |
36 |
// TESTS_RANGE = new int[] { 900, 999 }; |
36 |
// TESTS_RANGE = new int[] { 1050, 1099 }; |
37 |
} |
37 |
} |
38 |
|
38 |
|
39 |
public static Test suite() { |
39 |
public static Test suite() { |
Lines 44-56
Link Here
|
44 |
return NullReferenceTest.class; |
44 |
return NullReferenceTest.class; |
45 |
} |
45 |
} |
46 |
|
46 |
|
47 |
// Augment problem detection settings |
47 |
// Conditionally augment problem detection settings |
|
|
48 |
static boolean setNullRelatedOptions = true; |
48 |
protected Map getCompilerOptions() { |
49 |
protected Map getCompilerOptions() { |
49 |
Map defaultOptions = super.getCompilerOptions(); |
50 |
Map defaultOptions = super.getCompilerOptions(); |
50 |
// defaultOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING); |
51 |
if (setNullRelatedOptions) { |
51 |
defaultOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); |
52 |
defaultOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); |
52 |
defaultOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); |
53 |
defaultOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); |
53 |
// defaultOptions.put(CompilerOptions.OPTION_ReportNoEffectAssignment, CompilerOptions.WARNING); |
54 |
defaultOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); |
|
|
55 |
defaultOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); |
56 |
} |
54 |
return defaultOptions; |
57 |
return defaultOptions; |
55 |
} |
58 |
} |
56 |
|
59 |
|
Lines 7856-7862
Link Here
|
7856 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
7859 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
7857 |
"----------\n"); |
7860 |
"----------\n"); |
7858 |
} |
7861 |
} |
7859 |
|
7862 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 |
|
|
7863 |
// adding distinct options to control null checks in more detail |
7864 |
// default for null options is Ignore |
7865 |
public void test1050_options_all_default() { |
7866 |
try { |
7867 |
setNullRelatedOptions = false; |
7868 |
this.runConformTest( |
7869 |
new String[] { |
7870 |
"X.java", |
7871 |
"public class X {\n" + |
7872 |
" void foo(Object p) {\n" + |
7873 |
" Object o = null;\n" + |
7874 |
" if (o != null) {\n" + |
7875 |
" o = null;\n" + |
7876 |
" }\n" + |
7877 |
" if (p == null) {}\n" + // taint p |
7878 |
" o.toString();\n" + |
7879 |
" p.toString();\n" + |
7880 |
" }\n" + |
7881 |
"}\n"}); |
7882 |
} |
7883 |
finally { |
7884 |
setNullRelatedOptions = true; |
7885 |
} |
7886 |
} |
7887 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 |
7888 |
// adding distinct options to control null checks in more detail |
7889 |
// all null options set to Ignore |
7890 |
public void test1051_options_all_ignore() { |
7891 |
Map customOptions = getCompilerOptions(); |
7892 |
customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); |
7893 |
customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.IGNORE); |
7894 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); |
7895 |
this.runConformTest( |
7896 |
new String[] { |
7897 |
"X.java", |
7898 |
"public class X {\n" + |
7899 |
" void foo(Object p) {\n" + |
7900 |
" Object o = null;\n" + |
7901 |
" if (o != null) {\n" + |
7902 |
" o = null;\n" + |
7903 |
" }\n" + |
7904 |
" if (p == null) {}\n" + // taint p |
7905 |
" o.toString();\n" + |
7906 |
" p.toString();\n" + |
7907 |
" }\n" + |
7908 |
"}\n"}, |
7909 |
null /* no expected output string */, |
7910 |
null /* no extra class libraries */, |
7911 |
true /* flush output directory */, |
7912 |
null /* no vm arguments */, |
7913 |
customOptions, |
7914 |
null /* no custom requestor*/, |
7915 |
false /* do not skip javac for this peculiar test */); |
7916 |
} |
7917 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 |
7918 |
// adding distinct options to control null checks in more detail |
7919 |
// all options set to error |
7920 |
public void test1052_options_all_error() { |
7921 |
this.runNegativeTest( |
7922 |
new String[] { |
7923 |
"X.java", |
7924 |
"public class X {\n" + |
7925 |
" void foo(Object p) {\n" + |
7926 |
" Object o = null;\n" + |
7927 |
" if (o != null) {\n" + |
7928 |
" o = null;\n" + |
7929 |
" }\n" + |
7930 |
" if (p == null) {}\n" + // taint p |
7931 |
" o.toString();\n" + |
7932 |
" p.toString();\n" + |
7933 |
" }\n" + |
7934 |
"}\n"}, |
7935 |
"----------\n" + |
7936 |
"1. ERROR in X.java (at line 4)\r\n" + |
7937 |
" if (o != null) {\r\n" + |
7938 |
" ^\n" + |
7939 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
7940 |
"----------\n" + |
7941 |
"2. ERROR in X.java (at line 8)\r\n" + |
7942 |
" o.toString();\r\n" + |
7943 |
" ^\n" + |
7944 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
7945 |
"----------\n" + |
7946 |
"3. ERROR in X.java (at line 9)\r\n" + |
7947 |
" p.toString();\r\n" + |
7948 |
" ^\n" + |
7949 |
"The variable p may be null\n" + |
7950 |
"----------\n"); |
7951 |
} |
7952 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 |
7953 |
// adding distinct options to control null checks in more detail |
7954 |
// selectively changing error levels |
7955 |
public void test1053_options_mix() { |
7956 |
Map customOptions = getCompilerOptions(); |
7957 |
customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); |
7958 |
customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.IGNORE); |
7959 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); |
7960 |
this.runNegativeTest( |
7961 |
new String[] { |
7962 |
"X.java", |
7963 |
"public class X {\n" + |
7964 |
" void foo(Object p) {\n" + |
7965 |
" Object o = null;\n" + |
7966 |
" if (o != null) {\n" + |
7967 |
" o = null;\n" + |
7968 |
" }\n" + |
7969 |
" if (p == null) {}\n" + // taint p |
7970 |
" o.toString();\n" + |
7971 |
" p.toString();\n" + |
7972 |
" }\n" + |
7973 |
"}\n"}, |
7974 |
"----------\n" + |
7975 |
"1. ERROR in X.java (at line 8)\r\n" + |
7976 |
" o.toString();\r\n" + |
7977 |
" ^\n" + |
7978 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
7979 |
"----------\n", |
7980 |
null /* no extra class libraries */, |
7981 |
true /* flush output directory */, |
7982 |
customOptions, |
7983 |
false /* do not generate output */, |
7984 |
false /* do not show category */, |
7985 |
false /* do not show warning token */, |
7986 |
false /* do not skip javac for this peculiar test */, |
7987 |
false /* do not perform statements recovery */); |
7988 |
} |
7989 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 |
7990 |
// adding distinct options to control null checks in more detail |
7991 |
// selectively changing error levels |
7992 |
public void test1054_options_mix() { |
7993 |
Map customOptions = getCompilerOptions(); |
7994 |
customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING); |
7995 |
customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.IGNORE); |
7996 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); |
7997 |
this.runNegativeTest( |
7998 |
new String[] { |
7999 |
"X.java", |
8000 |
"public class X {\n" + |
8001 |
" void foo(Object p) {\n" + |
8002 |
" Object o = null;\n" + |
8003 |
" if (o != null) {\n" + |
8004 |
" o = null;\n" + |
8005 |
" }\n" + |
8006 |
" if (p == null) {}\n" + // taint p |
8007 |
" o.toString();\n" + |
8008 |
" p.toString();\n" + |
8009 |
" }\n" + |
8010 |
"}\n"}, |
8011 |
"----------\n" + |
8012 |
"1. ERROR in X.java (at line 4)\r\n" + |
8013 |
" if (o != null) {\r\n" + |
8014 |
" ^\n" + |
8015 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
8016 |
"----------\n" + |
8017 |
"2. WARNING in X.java (at line 8)\r\n" + |
8018 |
" o.toString();\r\n" + |
8019 |
" ^\n" + |
8020 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
8021 |
"----------\n", |
8022 |
null /* no extra class libraries */, |
8023 |
true /* flush output directory */, |
8024 |
customOptions, |
8025 |
false /* do not generate output */, |
8026 |
false /* do not show category */, |
8027 |
false /* do not show warning token */, |
8028 |
false /* do not skip javac for this peculiar test */, |
8029 |
false /* do not perform statements recovery */); |
8030 |
} |
8031 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 |
8032 |
// adding distinct options to control null checks in more detail |
8033 |
// selectively changing error levels |
8034 |
public void test1055_options_mix() { |
8035 |
Map customOptions = getCompilerOptions(); |
8036 |
customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); |
8037 |
customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); |
8038 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); |
8039 |
this.runNegativeTest( |
8040 |
new String[] { |
8041 |
"X.java", |
8042 |
"public class X {\n" + |
8043 |
" void foo(Object p) {\n" + |
8044 |
" Object o = null;\n" + |
8045 |
" if (o != null) {\n" + |
8046 |
" o = null;\n" + |
8047 |
" }\n" + |
8048 |
" if (p == null) {}\n" + // taint p |
8049 |
" o.toString();\n" + |
8050 |
" p.toString();\n" + |
8051 |
" }\n" + |
8052 |
"}\n"}, |
8053 |
"----------\n" + |
8054 |
"1. ERROR in X.java (at line 4)\r\n" + |
8055 |
" if (o != null) {\r\n" + |
8056 |
" ^\n" + |
8057 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
8058 |
"----------\n" + |
8059 |
"2. ERROR in X.java (at line 9)\r\n" + |
8060 |
" p.toString();\r\n" + |
8061 |
" ^\n" + |
8062 |
"The variable p may be null\n" + |
8063 |
"----------\n", |
8064 |
null /* no extra class libraries */, |
8065 |
true /* flush output directory */, |
8066 |
customOptions, |
8067 |
false /* do not generate output */, |
8068 |
false /* do not show category */, |
8069 |
false /* do not show warning token */, |
8070 |
false /* do not skip javac for this peculiar test */, |
8071 |
false /* do not perform statements recovery */); |
8072 |
} |
8073 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 |
8074 |
// adding distinct options to control null checks in more detail |
8075 |
// selectively changing error levels |
8076 |
public void test1056_options_mix_with_SuppressWarnings() { |
8077 |
if (complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) { |
8078 |
Map customOptions = getCompilerOptions(); |
8079 |
customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); |
8080 |
customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.WARNING); |
8081 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); |
8082 |
this.runNegativeTest( |
8083 |
new String[] { |
8084 |
"X.java", |
8085 |
"public class X {\n" + |
8086 |
"@SuppressWarnings(\"null\")\n" + |
8087 |
" void foo(Object p) {\n" + |
8088 |
" Object o = null;\n" + |
8089 |
" if (o != null) {\n" + |
8090 |
" o = null;\n" + |
8091 |
" }\n" + |
8092 |
" if (p == null) {}\n" + // taint p |
8093 |
" o.toString();\n" + |
8094 |
" p.toString();\n" + |
8095 |
" }\n" + |
8096 |
"}\n"}, |
8097 |
"----------\n" + |
8098 |
"1. ERROR in X.java (at line 9)\r\n" + |
8099 |
" o.toString();\r\n" + |
8100 |
" ^\n" + |
8101 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
8102 |
"----------\n", |
8103 |
null /* no extra class libraries */, |
8104 |
true /* flush output directory */, |
8105 |
customOptions, |
8106 |
false /* do not generate output */, |
8107 |
false /* do not show category */, |
8108 |
false /* do not show warning token */, |
8109 |
false /* do not skip javac for this peculiar test */, |
8110 |
false /* do not perform statements recovery */); |
8111 |
} |
8112 |
} |
8113 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 |
8114 |
// adding distinct options to control null checks in more detail |
8115 |
public void test1057_options_instanceof_is_check() { |
8116 |
this.runNegativeTest( |
8117 |
new String[] { |
8118 |
"X.java", |
8119 |
"public class X {\n" + |
8120 |
" void foo(Object p) {\n" + |
8121 |
" Object o = null;\n" + |
8122 |
" if (p == null) {}\n" + // taint p |
8123 |
" if (o instanceof String) {};\n" + |
8124 |
" if (p instanceof String) {};\n" + |
8125 |
" }\n" + |
8126 |
"}\n"}, |
8127 |
"----------\n" + |
8128 |
"1. ERROR in X.java (at line 5)\n" + |
8129 |
" if (o instanceof String) {};\n" + |
8130 |
" ^\n" + |
8131 |
"The variable o can only be null; it was either set to null or checked for null when last used\n" + |
8132 |
"----------\n"); |
8133 |
} |
8134 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 |
8135 |
// adding distinct options to control null checks in more detail |
8136 |
public void test1058_options_instanceof_is_check() { |
8137 |
Map customOptions = getCompilerOptions(); |
8138 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); |
8139 |
this.runConformTest( |
8140 |
new String[] { |
8141 |
"X.java", |
8142 |
"public class X {\n" + |
8143 |
" void foo(Object p) {\n" + |
8144 |
" Object o = null;\n" + |
8145 |
" if (p == null) {}\n" + // taint p |
8146 |
" if (o instanceof String) {};\n" + |
8147 |
" if (p instanceof String) {};\n" + |
8148 |
" }\n" + |
8149 |
"}\n"}, |
8150 |
null /* no expected output string */, |
8151 |
null /* no extra class libraries */, |
8152 |
true /* flush output directory */, |
8153 |
null /* no vm arguments */, |
8154 |
customOptions, |
8155 |
null /* no custom requestor*/, |
8156 |
false /* do not skip javac for this peculiar test */); |
8157 |
} |
8158 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 |
8159 |
// adding distinct options to control null checks in more detail |
8160 |
public void test1059_options_cannot_be_null_check() { |
8161 |
Map customOptions = getCompilerOptions(); |
8162 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); |
8163 |
this.runConformTest( |
8164 |
new String[] { |
8165 |
"X.java", |
8166 |
"public class X {\n" + |
8167 |
" void foo(Object p) {\n" + |
8168 |
" Object o = new Object();\n" + |
8169 |
" if (o == null) {}\n" + |
8170 |
" }\n" + |
8171 |
"}\n"}, |
8172 |
null /* no expected output string */, |
8173 |
null /* no extra class libraries */, |
8174 |
true /* flush output directory */, |
8175 |
null /* no vm arguments */, |
8176 |
customOptions, |
8177 |
null /* no custom requestor*/, |
8178 |
false /* do not skip javac for this peculiar test */); |
8179 |
} |
7860 |
// encoding validation |
8180 |
// encoding validation |
7861 |
public void test1500() { |
8181 |
public void test1500() { |
7862 |
this.runConformTest( |
8182 |
this.runConformTest( |