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 161856 Details for
Bug 305590
Redundant null check false-positive
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
proposed fix v1.0 + regression tests
patchInstanceof.txt (text/plain), 3.64 KB, created by
Ayushman Jain
on 2010-03-12 05:36:54 EST
(
hide
)
Description:
proposed fix v1.0 + regression tests
Filename:
MIME Type:
Creator:
Ayushman Jain
Created:
2010-03-12 05:36:54 EST
Size:
3.64 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java,v >retrieving revision 1.59 >diff -u -r1.59 InstanceOfExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java 7 Mar 2009 01:08:07 -0000 1.59 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/InstanceOfExpression.java 12 Mar 2010 10:33:31 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2009 IBM Corporation and others. >+ * Copyright (c) 2000, 2010 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 >@@ -32,12 +32,12 @@ > public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { > LocalVariableBinding local = this.expression.localVariableBinding(); > if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0) { >- flowContext.recordUsingNullReference(currentScope, local, >- this.expression, FlowContext.CAN_ONLY_NULL | FlowContext.IN_INSTANCEOF, flowInfo); > flowInfo = this.expression.analyseCode(currentScope, flowContext, flowInfo). > unconditionalInits(); > FlowInfo initsWhenTrue = flowInfo.copy(); > initsWhenTrue.markAsComparedEqualToNonNull(local); >+ flowContext.recordUsingNullReference(currentScope, local, >+ this.expression, FlowContext.CAN_ONLY_NULL | FlowContext.IN_INSTANCEOF, flowInfo); > // no impact upon enclosing try context > return FlowInfo.conditional(initsWhenTrue, flowInfo.copy()); > } >#P org.eclipse.jdt.core.tests.compiler >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.94 >diff -u -r1.94 NullReferenceTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 3 Mar 2010 18:37:13 -0000 1.94 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 12 Mar 2010 10:34:53 -0000 >@@ -11636,4 +11636,30 @@ > " 12 return\n"; > checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); > } >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=305590 >+// To verify that a "instanceof always yields false" warning is not elicited in the >+// case when the expression has been assigned a non null value in the instanceof check. >+public void testBug305590() { >+ runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public void foo() {\n" + >+ " Object str = null;\n" + >+ " if ((str = \"str\") instanceof String) {}\n" + // shouldn't warn >+ " str = null;\n" + >+ " if ((str = \"str\") instanceof Number) {}\n" + // shouldn't warn >+ " str = null;\n" + >+ " if (str instanceof String) {}\n" + // should warn >+ " }\n" + >+ "}"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 8)\n" + >+ " if (str instanceof String) {}\n" + >+ " ^^^\n" + >+ "instanceof always yields false: The variable str can only be null at this location\n" + >+ "----------\n", >+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); >+} > } >\ No newline at end of file
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
Flags:
Olivier_Thomann
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 305590
: 161856