Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 58555 Details for
Bug 170704
[compiler][null][enh] separate "null dereference" and "null reference" compiler options
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Suggested fix + test cases
patch.txt (text/plain), 37.88 KB, created by
Maxime Daniel
on 2007-02-08 09:12:22 EST
(
hide
)
Description:
Suggested fix + test cases
Filename:
MIME Type:
Creator:
Maxime Daniel
Created:
2007-02-08 09:12:22 EST
Size:
37.88 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/core/compiler/IProblem.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java,v >retrieving revision 1.186 >diff -u -r1.186 IProblem.java >--- compiler/org/eclipse/jdt/core/compiler/IProblem.java 31 Jan 2007 19:31:44 -0000 1.186 >+++ compiler/org/eclipse/jdt/core/compiler/IProblem.java 8 Feb 2007 14:08:10 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -719,11 +719,14 @@ > int DuplicateModifierForVariable = MethodRelated + 395; > int IllegalModifierForVariable = MethodRelated + 396; > /** @since 3.1 */ >- int LocalVariableCannotBeNull = Internal + 397; >+ int LocalVariableCannotBeNull = Internal + 397; // since 3.3: semantics are LocalVariableRedundantCheckOnNonNull > /** @since 3.1 */ >- int LocalVariableCanOnlyBeNull = Internal + 398; >+ int LocalVariableCanOnlyBeNull = Internal + 398; // since 3.3: split with LocalVariableRedundantCheckOnNull depending on context >+ // this id shares the null dereference errors with LocalVariableMayBeNull > /** @since 3.2 */ > int LocalVariableMayBeNull = Internal + 399; >+ /** @since 3.3 */ >+ int LocalVariableRedundantCheckOnNull = Internal + 392; > > // method verifier problems > int AbstractMethodMustBeImplemented = MethodRelated + 400; >Index: batch/org/eclipse/jdt/internal/compiler/batch/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties,v >retrieving revision 1.598 >diff -u -r1.598 messages.properties >--- batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 31 Jan 2007 07:11:46 -0000 1.598 >+++ batch/org/eclipse/jdt/internal/compiler/batch/messages.properties 8 Feb 2007 14:08:09 -0000 >@@ -248,7 +248,8 @@ > \ maskedCatchBlock + hidden catch block\n\ > \ nls string literal lacking non-nls tag //$NON-NLS-<n>$\n\ > \ noEffectAssign + assignment without effect\n\ >-\ null missing or redundant null check\n\ >+\ null potential missing or redundant null check\n\ >+\ nullDereference missing null check\n\ > \ over-ann missing @Override annotation\n\ > \ paramAssign assignment to a parameter\n\ > \ pkgDefaultMethod + attempt to override package-default method\n\ >Index: batch/org/eclipse/jdt/internal/compiler/batch/Main.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java,v >retrieving revision 1.279 >diff -u -r1.279 Main.java >--- batch/org/eclipse/jdt/internal/compiler/batch/Main.java 1 Feb 2007 15:38:49 -0000 1.279 >+++ batch/org/eclipse/jdt/internal/compiler/batch/Main.java 8 Feb 2007 14:08:09 -0000 >@@ -1601,9 +1601,20 @@ > CompilerOptions.OPTION_ReportVarargsArgumentNeedCast, > isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); > } else if (token.equals("null")) { //$NON-NLS-1$ >+ if (isEnabling) { >+ this.options.put(CompilerOptions.OPTION_ReportNullReference, >+ CompilerOptions.WARNING); >+ this.options.put(CompilerOptions.OPTION_ReportPotentialNullReference, >+ CompilerOptions.WARNING); >+ this.options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, >+ CompilerOptions.WARNING); >+ } >+ } else if (token.equals("nullDereference")) { //$NON-NLS-1$ > this.options.put( > CompilerOptions.OPTION_ReportNullReference, >- isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); >+ isEnabling ? CompilerOptions.WARNING : CompilerOptions.IGNORE); >+ // no need to position OPTION_ReportPotentialNullReference or >+ // OPTION_ReportRedundantNullCheck, which are ignored by default > } else if (token.equals("boxing")) { //$NON-NLS-1$ > this.options.put( > CompilerOptions.OPTION_ReportAutoboxing, >Index: compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties,v >retrieving revision 1.216 >diff -u -r1.216 messages.properties >--- compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 31 Jan 2007 19:31:44 -0000 1.216 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties 8 Feb 2007 14:08:12 -0000 >@@ -320,6 +320,7 @@ > ###[obsolete] 394 = The imported type {0} is defined in an inherited type and an enclosing scope > > 391 = The static import {0} must be a field or member type >+392 = The variable {0} can only be null; it was either set to null or checked for null when last used > > 395 = Duplicate modifier for the variable {0} > 396 = Illegal modifier for the variable {0}; only final is permitted >Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java,v >retrieving revision 1.338 >diff -u -r1.338 ProblemReporter.java >--- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 31 Jan 2007 19:31:44 -0000 1.338 >+++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java 8 Feb 2007 14:08:12 -0000 >@@ -184,10 +184,15 @@ > case IProblem.ConstructorVarargsArgumentNeedCast : > return CompilerOptions.VarargsArgumentNeedCast; > >- case IProblem.LocalVariableCannotBeNull : >- case IProblem.LocalVariableCanOnlyBeNull : >- case IProblem.LocalVariableMayBeNull : >+ case IProblem.LocalVariableCanOnlyBeNull: > return CompilerOptions.NullReference; >+ >+ case IProblem.LocalVariableMayBeNull: >+ return CompilerOptions.PotentialNullReference; >+ >+ case IProblem.LocalVariableCannotBeNull: >+ case IProblem.LocalVariableRedundantCheckOnNull: >+ return CompilerOptions.RedundantNullCheck; > > case IProblem.BoxingConversion : > case IProblem.UnboxingConversion : >@@ -4385,7 +4390,7 @@ > if (severity == ProblemSeverities.Ignore) return; > String[] arguments = new String[] {new String(local.name) }; > this.handle( >- IProblem.LocalVariableCanOnlyBeNull, >+ IProblem.LocalVariableCanOnlyBeNull, > arguments, > arguments, > severity, >@@ -4438,6 +4443,18 @@ > nodeSourceStart(local, location), > nodeSourceEnd(local, location)); > } >+public void localVariableRedundantCheckOnNull(LocalVariableBinding local, ASTNode location) { >+ int severity = computeSeverity(IProblem.LocalVariableRedundantCheckOnNull); >+ if (severity == ProblemSeverities.Ignore) return; >+ String[] arguments = new String[] {new String(local.name) }; >+ this.handle( >+ IProblem.LocalVariableRedundantCheckOnNull, >+ arguments, >+ arguments, >+ severity, >+ nodeSourceStart(local, location), >+ nodeSourceEnd(local, location)); >+} > public void methodMustOverride(AbstractMethodDeclaration method) { > MethodBinding binding = method.binding; > this.handle( >Index: compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java,v >retrieving revision 1.21 >diff -u -r1.21 FinallyFlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 25 Sep 2006 11:36:59 -0000 1.21 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 8 Feb 2007 14:08:10 -0000 >@@ -99,7 +99,7 @@ > } > case CAN_ONLY_NULL: > if (flowInfo.isDefinitelyNull(local)) { >- scope.problemReporter().localVariableCanOnlyBeNull(local, expression); >+ scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); > } > break; > case MAY_NULL : >@@ -170,7 +170,7 @@ > return; > } > if (flowInfo.canOnlyBeNull(local)) { >- scope.problemReporter().localVariableCanOnlyBeNull(local, reference); >+ scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > return; > } > break; >@@ -196,7 +196,7 @@ > } > case CAN_ONLY_NULL: > if (flowInfo.isDefinitelyNull(local)) { >- scope.problemReporter().localVariableCanOnlyBeNull(local, reference); >+ scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > return; > } > break; >Index: compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java,v >retrieving revision 1.35 >diff -u -r1.35 LoopingFlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 26 Sep 2006 12:04:03 -0000 1.35 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 8 Feb 2007 14:08:10 -0000 >@@ -136,14 +136,14 @@ > } > if (flowInfo.isDefinitelyNull(local)) { > this.nullReferences[i] = null; >- scope.problemReporter().localVariableCanOnlyBeNull(local, expression); >+ scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); > continue; > } > break; > case CAN_ONLY_NULL : > if (flowInfo.isDefinitelyNull(local)) { > this.nullReferences[i] = null; >- scope.problemReporter().localVariableCanOnlyBeNull(local, expression); >+ scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); > continue; > } > break; >@@ -177,7 +177,7 @@ > case CAN_ONLY_NULL : > if (flowInfo.isDefinitelyNull(local)) { > this.nullReferences[i] = null; >- scope.problemReporter().localVariableCanOnlyBeNull(local, expression); >+ scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); > continue; > } > break; >@@ -329,7 +329,7 @@ > return; > } > if (flowInfo.isDefinitelyNull(local)) { >- scope.problemReporter().localVariableCanOnlyBeNull(local, reference); >+ scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > return; > } > if (flowInfo.cannotBeDefinitelyNullOrNonNull(local)) { >@@ -347,7 +347,7 @@ > return; > } > if (flowInfo.isDefinitelyNull(local)) { >- scope.problemReporter().localVariableCanOnlyBeNull(local, reference); >+ scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > return; > } > recordNullReference(local, reference, checkType); >Index: compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java,v >retrieving revision 1.53 >diff -u -r1.53 FlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 26 Sep 2006 12:04:03 -0000 1.53 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 8 Feb 2007 14:08:10 -0000 >@@ -508,7 +508,7 @@ > } > case CAN_ONLY_NULL: > if (flowInfo.isDefinitelyNull(local)) { >- scope.problemReporter().localVariableCanOnlyBeNull(local, reference); >+ scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > return; > } > else if (flowInfo.cannotBeDefinitelyNullOrNonNull(local)) { >Index: compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java,v >retrieving revision 1.177 >diff -u -r1.177 CompilerOptions.java >--- compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 14 Dec 2006 18:31:06 -0000 1.177 >+++ compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 8 Feb 2007 14:08:10 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -94,6 +94,8 @@ > public static final String OPTION_TaskCaseSensitive = "org.eclipse.jdt.core.compiler.taskCaseSensitive"; //$NON-NLS-1$ > public static final String OPTION_InlineJsr = "org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode"; //$NON-NLS-1$ > public static final String OPTION_ReportNullReference = "org.eclipse.jdt.core.compiler.problem.nullReference"; //$NON-NLS-1$ >+ public static final String OPTION_ReportPotentialNullReference = "org.eclipse.jdt.core.compiler.problem.potentialNullReference"; //$NON-NLS-1$ >+ public static final String OPTION_ReportRedundantNullCheck = "org.eclipse.jdt.core.compiler.problem.redundantNullCheck"; //$NON-NLS-1$ > public static final String OPTION_ReportAutoboxing = "org.eclipse.jdt.core.compiler.problem.autoboxing"; //$NON-NLS-1$ > public static final String OPTION_ReportAnnotationSuperInterface = "org.eclipse.jdt.core.compiler.problem.annotationSuperInterface"; //$NON-NLS-1$ > public static final String OPTION_ReportMissingOverrideAnnotation = "org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation"; //$NON-NLS-1$ >@@ -194,6 +196,9 @@ > public static final long ParameterAssignment = ASTNode.Bit48L; > public static final long FallthroughCase = ASTNode.Bit49L; > public static final long OverridingMethodWithoutSuperInvocation = ASTNode.Bit50L; >+ public static final long PotentialNullReference = ASTNode.Bit51L; >+ public static final long RedundantNullCheck = ASTNode.Bit52L; >+ > > // Default severity level for handlers > public long errorThreshold = 0; >@@ -413,7 +418,9 @@ > optionsMap.put(OPTION_MaxProblemPerUnit, String.valueOf(this.maxProblemsPerUnit)); > optionsMap.put(OPTION_InlineJsr, this.inlineJsrBytecode ? ENABLED : DISABLED); > optionsMap.put(OPTION_ReportNullReference, getSeverityString(NullReference)); >- optionsMap.put(OPTION_SuppressWarnings, this.suppressWarnings ? ENABLED : DISABLED); >+ optionsMap.put(OPTION_ReportPotentialNullReference, getSeverityString(PotentialNullReference)); >+ optionsMap.put(OPTION_ReportRedundantNullCheck, getSeverityString(RedundantNullCheck)); >+ optionsMap.put(OPTION_SuppressWarnings, this.suppressWarnings ? ENABLED : DISABLED); > optionsMap.put(OPTION_ReportUnhandledWarningToken, getSeverityString(UnhandledWarningToken)); > optionsMap.put(OPTION_ReportParameterAssignment, getSeverityString(ParameterAssignment)); > optionsMap.put(OPTION_ReportFallthroughCase, getSeverityString(FallthroughCase)); >@@ -652,6 +659,8 @@ > if ((optionValue = optionsMap.get(OPTION_ReportDiscouragedReference)) != null) updateSeverity(DiscouragedReference, optionValue); > if ((optionValue = optionsMap.get(OPTION_ReportVarargsArgumentNeedCast)) != null) updateSeverity(VarargsArgumentNeedCast, optionValue); > if ((optionValue = optionsMap.get(OPTION_ReportNullReference)) != null) updateSeverity(NullReference, optionValue); >+ if ((optionValue = optionsMap.get(OPTION_ReportPotentialNullReference)) != null) updateSeverity(PotentialNullReference, optionValue); >+ if ((optionValue = optionsMap.get(OPTION_ReportRedundantNullCheck)) != null) updateSeverity(RedundantNullCheck, optionValue); > if ((optionValue = optionsMap.get(OPTION_ReportAutoboxing)) != null) updateSeverity(AutoBoxing, optionValue); > if ((optionValue = optionsMap.get(OPTION_ReportAnnotationSuperInterface)) != null) updateSeverity(AnnotationSuperInterface, optionValue); > if ((optionValue = optionsMap.get(OPTION_ReportMissingOverrideAnnotation)) != null) updateSeverity(MissingOverrideAnnotation, optionValue); >@@ -959,6 +968,8 @@ > OPTION_ReportNonExternalizedStringLiteral, > OPTION_ReportNonStaticAccessToStatic, > OPTION_ReportNullReference, >+ OPTION_ReportPotentialNullReference, >+ OPTION_ReportRedundantNullCheck, > OPTION_ReportOverridingPackageDefaultMethod, > OPTION_ReportParameterAssignment, > OPTION_ReportPossibleAccidentalBooleanAssignment, >@@ -1106,7 +1117,7 @@ > if ("nls".equals(warningToken)) //$NON-NLS-1$ > return NonExternalizedString; > if ("null".equals(warningToken)) //$NON-NLS-1$ >- return NullReference; >+ return NullReference | PotentialNullReference | RedundantNullCheck; > break; > case 'r' : > if ("restriction".equals(warningToken)) //$NON-NLS-1$ >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java,v >retrieving revision 1.34 >diff -u -r1.34 AssignmentTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 6 Dec 2006 16:56:38 -0000 1.34 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java 8 Feb 2007 14:08:15 -0000 >@@ -24,6 +24,8 @@ > protected Map getCompilerOptions() { > Map options = super.getCompilerOptions(); > options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); >+ options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); >+ options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); > options.put(CompilerOptions.OPTION_ReportNoEffectAssignment, CompilerOptions.ERROR); > return options; > } >Index: src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java,v >retrieving revision 1.101 >diff -u -r1.101 BatchCompilerTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 1 Feb 2007 15:38:45 -0000 1.101 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 8 Feb 2007 14:08:16 -0000 >@@ -37,7 +37,7 @@ > static { > // TESTS_NAMES = new String[] { "test000" }; > // TESTS_NUMBERS = new int[] { 59 }; >-// TESTS_RANGE = new int[] { 107, -1 }; >+// TESTS_RANGE = new int[] { 122, -1 }; > } > public BatchCompilerTest(String name) { > super(name); >@@ -1116,7 +1116,8 @@ > " maskedCatchBlock + hidden catch block\n" + > " nls string literal lacking non-nls tag //$NON-NLS-<n>$\n" + > " noEffectAssign + assignment without effect\n" + >- " null missing or redundant null check\n" + >+ " null potential missing or redundant null check\n" + >+ " nullDereference missing null check\n" + > " over-ann missing @Override annotation\n" + > " paramAssign assignment to a parameter\n" + > " pkgDefaultMethod + attempt to override package-default method\n" + >@@ -1262,7 +1263,9 @@ > " <option key=\"org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod\" value=\"warning\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.parameterAssignment\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment\" value=\"ignore\"/>\n" + >+ " <option key=\"org.eclipse.jdt.core.compiler.problem.potentialNullReference\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.rawTypeReference\" value=\"warning\"/>\n" + >+ " <option key=\"org.eclipse.jdt.core.compiler.problem.redundantNullCheck\" value=\"ignore\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.specialParameterHidingField\" value=\"disabled\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.staticAccessReceiver\" value=\"warning\"/>\n" + > " <option key=\"org.eclipse.jdt.core.compiler.problem.suppressWarnings\" value=\"enabled\"/>\n" + >@@ -5164,6 +5167,87 @@ > null, > null); > } >+// null ref option >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 >+// adding distinct options to control null checks in more detail >+public void test139_null_ref_option(){ >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void foo() {\n" + >+ " Object o = null;\n" + >+ " o.toString();\n" + >+ " }\n" + >+ "}"}, >+ "\"" + OUTPUT_DIR + File.separator + "X.java\"" >+ + " -1.5 -g -preserveAllLocals" >+ + " -bootclasspath " + getLibraryClasses() >+ + " -cp " + getJCEJar() >+ + " -warn:+nullDereference" >+ + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", >+ "", >+ "----------\n" + >+ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" + >+ " o.toString();\n" + >+ " ^\n" + >+ "The variable o can only be null; it was either set to null or checked for null when last used\n" + >+ "----------\n" + >+ "1 problem (1 warning)", >+ true); >+} >+// null ref option >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 >+// adding distinct options to control null checks in more detail >+public void test140_null_ref_option(){ >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void foo() {\n" + >+ " Object o = null;\n" + >+ " if (o == null) {}\n" + >+ " }\n" + >+ "}"}, >+ "\"" + OUTPUT_DIR + File.separator + "X.java\"" >+ + " -1.5 -g -preserveAllLocals" >+ + " -bootclasspath " + getLibraryClasses() >+ + " -cp " + getJCEJar() >+ + " -warn:+null" >+ + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", >+ "", >+ "----------\n" + >+ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" + >+ " if (o == null) {}\n" + >+ " ^\n" + >+ "The variable o can only be null; it was either set to null or checked for null when last used\n" + >+ "----------\n" + >+ "1 problem (1 warning)", >+ true); >+} >+// null ref option >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 >+// adding distinct options to control null checks in more detail >+public void test141_null_ref_option(){ >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void foo() {\n" + >+ " Object o = null;\n" + >+ " if (o == null) {}\n" + >+ " }\n" + >+ "}"}, >+ "\"" + OUTPUT_DIR + File.separator + "X.java\"" >+ + " -1.5 -g -preserveAllLocals" >+ + " -bootclasspath " + getLibraryClasses() >+ + " -cp " + getJCEJar() >+ + " -warn:+nullDereference" >+ + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", >+ "", >+ "", >+ true); >+} > public static Class testClass() { > return BatchCompilerTest.class; > } >Index: src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java,v >retrieving revision 1.51 >diff -u -r1.51 NullReferenceTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 22 Nov 2006 09:11:39 -0000 1.51 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 8 Feb 2007 14:08:19 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2006 IBM Corporation and others. >+ * Copyright (c) 2005, 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -33,7 +33,7 @@ > // TESTS_RANGE = new int[] { 2050, -1 }; > // TESTS_RANGE = new int[] { 1, 2049 }; > // TESTS_RANGE = new int[] { 449, 451 }; >-// TESTS_RANGE = new int[] { 900, 999 }; >+// TESTS_RANGE = new int[] { 1050, 1099 }; > } > > public static Test suite() { >@@ -44,13 +44,16 @@ > return NullReferenceTest.class; > } > >-// Augment problem detection settings >+// Conditionally augment problem detection settings >+static boolean setNullRelatedOptions = true; > protected Map getCompilerOptions() { > Map defaultOptions = super.getCompilerOptions(); >-// defaultOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING); >- defaultOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); >- defaultOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); >-// defaultOptions.put(CompilerOptions.OPTION_ReportNoEffectAssignment, CompilerOptions.WARNING); >+ if (setNullRelatedOptions) { >+ defaultOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); >+ defaultOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); >+ defaultOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); >+ defaultOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); >+ } > return defaultOptions; > } > >@@ -7856,7 +7859,324 @@ > "The variable o can only be null; it was either set to null or checked for null when last used\n" + > "----------\n"); > } >- >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 >+// adding distinct options to control null checks in more detail >+// default for null options is Ignore >+public void test1050_options_all_default() { >+ try { >+ setNullRelatedOptions = false; >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void foo(Object p) {\n" + >+ " Object o = null;\n" + >+ " if (o != null) {\n" + >+ " o = null;\n" + >+ " }\n" + >+ " if (p == null) {}\n" + // taint p >+ " o.toString();\n" + >+ " p.toString();\n" + >+ " }\n" + >+ "}\n"}); >+ } >+ finally { >+ setNullRelatedOptions = true; >+ } >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 >+// adding distinct options to control null checks in more detail >+// all null options set to Ignore >+public void test1051_options_all_ignore() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); >+ customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.IGNORE); >+ customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void foo(Object p) {\n" + >+ " Object o = null;\n" + >+ " if (o != null) {\n" + >+ " o = null;\n" + >+ " }\n" + >+ " if (p == null) {}\n" + // taint p >+ " o.toString();\n" + >+ " p.toString();\n" + >+ " }\n" + >+ "}\n"}, >+ null /* no expected output string */, >+ null /* no extra class libraries */, >+ true /* flush output directory */, >+ null /* no vm arguments */, >+ customOptions, >+ null /* no custom requestor*/, >+ false /* do not skip javac for this peculiar test */); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 >+// adding distinct options to control null checks in more detail >+// all options set to error >+public void test1052_options_all_error() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void foo(Object p) {\n" + >+ " Object o = null;\n" + >+ " if (o != null) {\n" + >+ " o = null;\n" + >+ " }\n" + >+ " if (p == null) {}\n" + // taint p >+ " o.toString();\n" + >+ " p.toString();\n" + >+ " }\n" + >+ "}\n"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\r\n" + >+ " if (o != null) {\r\n" + >+ " ^\n" + >+ "The variable o can only be null; it was either set to null or checked for null when last used\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 8)\r\n" + >+ " o.toString();\r\n" + >+ " ^\n" + >+ "The variable o can only be null; it was either set to null or checked for null when last used\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 9)\r\n" + >+ " p.toString();\r\n" + >+ " ^\n" + >+ "The variable p may be null\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 >+// adding distinct options to control null checks in more detail >+// selectively changing error levels >+public void test1053_options_mix() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); >+ customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.IGNORE); >+ customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void foo(Object p) {\n" + >+ " Object o = null;\n" + >+ " if (o != null) {\n" + >+ " o = null;\n" + >+ " }\n" + >+ " if (p == null) {}\n" + // taint p >+ " o.toString();\n" + >+ " p.toString();\n" + >+ " }\n" + >+ "}\n"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 8)\r\n" + >+ " o.toString();\r\n" + >+ " ^\n" + >+ "The variable o can only be null; it was either set to null or checked for null when last used\n" + >+ "----------\n", >+ null /* no extra class libraries */, >+ true /* flush output directory */, >+ customOptions, >+ false /* do not generate output */, >+ false /* do not show category */, >+ false /* do not show warning token */, >+ false /* do not skip javac for this peculiar test */, >+ false /* do not perform statements recovery */); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 >+// adding distinct options to control null checks in more detail >+// selectively changing error levels >+public void test1054_options_mix() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING); >+ customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.IGNORE); >+ customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void foo(Object p) {\n" + >+ " Object o = null;\n" + >+ " if (o != null) {\n" + >+ " o = null;\n" + >+ " }\n" + >+ " if (p == null) {}\n" + // taint p >+ " o.toString();\n" + >+ " p.toString();\n" + >+ " }\n" + >+ "}\n"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\r\n" + >+ " if (o != null) {\r\n" + >+ " ^\n" + >+ "The variable o can only be null; it was either set to null or checked for null when last used\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 8)\r\n" + >+ " o.toString();\r\n" + >+ " ^\n" + >+ "The variable o can only be null; it was either set to null or checked for null when last used\n" + >+ "----------\n", >+ null /* no extra class libraries */, >+ true /* flush output directory */, >+ customOptions, >+ false /* do not generate output */, >+ false /* do not show category */, >+ false /* do not show warning token */, >+ false /* do not skip javac for this peculiar test */, >+ false /* do not perform statements recovery */); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 >+// adding distinct options to control null checks in more detail >+// selectively changing error levels >+public void test1055_options_mix() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); >+ customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); >+ customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void foo(Object p) {\n" + >+ " Object o = null;\n" + >+ " if (o != null) {\n" + >+ " o = null;\n" + >+ " }\n" + >+ " if (p == null) {}\n" + // taint p >+ " o.toString();\n" + >+ " p.toString();\n" + >+ " }\n" + >+ "}\n"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\r\n" + >+ " if (o != null) {\r\n" + >+ " ^\n" + >+ "The variable o can only be null; it was either set to null or checked for null when last used\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 9)\r\n" + >+ " p.toString();\r\n" + >+ " ^\n" + >+ "The variable p may be null\n" + >+ "----------\n", >+ null /* no extra class libraries */, >+ true /* flush output directory */, >+ customOptions, >+ false /* do not generate output */, >+ false /* do not show category */, >+ false /* do not show warning token */, >+ false /* do not skip javac for this peculiar test */, >+ false /* do not perform statements recovery */); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 >+// adding distinct options to control null checks in more detail >+// selectively changing error levels >+public void test1056_options_mix_with_SuppressWarnings() { >+ if (complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); >+ customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.WARNING); >+ customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ "@SuppressWarnings(\"null\")\n" + >+ " void foo(Object p) {\n" + >+ " Object o = null;\n" + >+ " if (o != null) {\n" + >+ " o = null;\n" + >+ " }\n" + >+ " if (p == null) {}\n" + // taint p >+ " o.toString();\n" + >+ " p.toString();\n" + >+ " }\n" + >+ "}\n"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 9)\r\n" + >+ " o.toString();\r\n" + >+ " ^\n" + >+ "The variable o can only be null; it was either set to null or checked for null when last used\n" + >+ "----------\n", >+ null /* no extra class libraries */, >+ true /* flush output directory */, >+ customOptions, >+ false /* do not generate output */, >+ false /* do not show category */, >+ false /* do not show warning token */, >+ false /* do not skip javac for this peculiar test */, >+ false /* do not perform statements recovery */); >+ } >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 >+// adding distinct options to control null checks in more detail >+public void test1057_options_instanceof_is_check() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void foo(Object p) {\n" + >+ " Object o = null;\n" + >+ " if (p == null) {}\n" + // taint p >+ " if (o instanceof String) {};\n" + >+ " if (p instanceof String) {};\n" + >+ " }\n" + >+ "}\n"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " if (o instanceof String) {};\n" + >+ " ^\n" + >+ "The variable o can only be null; it was either set to null or checked for null when last used\n" + >+ "----------\n"); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 >+// adding distinct options to control null checks in more detail >+public void test1058_options_instanceof_is_check() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void foo(Object p) {\n" + >+ " Object o = null;\n" + >+ " if (p == null) {}\n" + // taint p >+ " if (o instanceof String) {};\n" + >+ " if (p instanceof String) {};\n" + >+ " }\n" + >+ "}\n"}, >+ null /* no expected output string */, >+ null /* no extra class libraries */, >+ true /* flush output directory */, >+ null /* no vm arguments */, >+ customOptions, >+ null /* no custom requestor*/, >+ false /* do not skip javac for this peculiar test */); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 >+// adding distinct options to control null checks in more detail >+public void test1059_options_cannot_be_null_check() { >+ Map customOptions = getCompilerOptions(); >+ customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " void foo(Object p) {\n" + >+ " Object o = new Object();\n" + >+ " if (o == null) {}\n" + >+ " }\n" + >+ "}\n"}, >+ null /* no expected output string */, >+ null /* no extra class libraries */, >+ true /* flush output directory */, >+ null /* no vm arguments */, >+ customOptions, >+ null /* no custom requestor*/, >+ false /* do not skip javac for this peculiar test */); >+} > // encoding validation > public void test1500() { > this.runConformTest(
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 170704
:
56990
|
56991
|
56992
| 58555