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 160043 Details for
Bug 303448
Wrong code generation optimization when assert condition is false
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
proposed fix v0.5 + regression tests
patchAssertProbs.txt (text/plain), 62.28 KB, created by
Ayushman Jain
on 2010-02-24 05:14:26 EST
(
hide
)
Description:
proposed fix v0.5 + regression tests
Filename:
MIME Type:
Creator:
Ayushman Jain
Created:
2010-02-24 05:14:26 EST
Size:
62.28 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java,v >retrieving revision 1.78 >diff -u -r1.78 EqualExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java 11 Feb 2010 01:32:26 -0000 1.78 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/EqualExpression.java 24 Feb 2010 10:08:44 -0000 >@@ -47,6 +47,9 @@ > initsWhenTrue.markAsComparedEqualToNonNull(local); // from thereon it is set > initsWhenFalse.markAsComparedEqualToNull(local); // from thereon it is set > } >+ if (flowContext.hideNullComparisonWarnings) { >+ flowInfo.markedAsNullOrNonNullInAssertExpression(local); >+ } > break; > case FlowInfo.NON_NULL : > if (((this.bits & OperatorMASK) >> OperatorSHIFT) == EQUAL_EQUAL) { >Index: compiler/org/eclipse/jdt/internal/compiler/flow/ConditionalFlowInfo.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/ConditionalFlowInfo.java,v >retrieving revision 1.29 >diff -u -r1.29 ConditionalFlowInfo.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/ConditionalFlowInfo.java 7 Mar 2009 01:08:10 -0000 1.29 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/ConditionalFlowInfo.java 24 Feb 2010 10:08:44 -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 >@@ -214,4 +214,14 @@ > return this.initsWhenTrue.unconditionalCopy(). > mergedWith(this.initsWhenFalse.unconditionalInits()); > } >+ >+public void markedAsNullOrNonNullInAssertExpression(LocalVariableBinding local) { >+ this.initsWhenTrue.markedAsNullOrNonNullInAssertExpression(local); >+ this.initsWhenFalse.markedAsNullOrNonNullInAssertExpression(local); >+} >+ >+public boolean isMarkedAsNullOrNonNullInAssertExpression(LocalVariableBinding local) { >+ return (this.initsWhenTrue.isMarkedAsNullOrNonNullInAssertExpression(local) >+ || this.initsWhenFalse.isMarkedAsNullOrNonNullInAssertExpression(local)); >+} > } >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.33 >diff -u -r1.33 FinallyFlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 23 Feb 2010 18:27:09 -0000 1.33 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 24 Feb 2010 10:08:45 -0000 >@@ -228,12 +228,16 @@ > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); > } >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ } > } else if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) { > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNonNullComparedToNull(local, reference); > } >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ } > } > return; > } >@@ -247,7 +251,9 @@ > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > } >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ } > return; > case FlowContext.IN_COMPARISON_NON_NULL: > if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >@@ -257,7 +263,9 @@ > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ } > return; > case FlowContext.IN_ASSIGNMENT: > scope.problemReporter().localVariableRedundantNullAssignment(local, reference); >@@ -305,12 +313,16 @@ > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); > } >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ } > } else { > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNonNullComparedToNull(local, reference); > } >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ } > } > return; > } >@@ -329,7 +341,9 @@ > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > } >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ } > return; > case FlowContext.IN_COMPARISON_NON_NULL: > if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >@@ -339,7 +353,9 @@ > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ } > return; > case FlowContext.IN_ASSIGNMENT: > scope.problemReporter().localVariableRedundantNullAssignment(local, reference); >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.64 >diff -u -r1.64 FlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 23 Feb 2010 18:27:09 -0000 1.64 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 24 Feb 2010 10:08:45 -0000 >@@ -550,12 +550,16 @@ > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); > } >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ } > } else { > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNonNullComparedToNull(local, reference); > } >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ } > } > return; > } >@@ -577,7 +581,9 @@ > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > } >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ } > return; > case FlowContext.IN_COMPARISON_NON_NULL: > if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >@@ -587,7 +593,9 @@ > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ } > return; > case FlowContext.IN_ASSIGNMENT: > scope.problemReporter().localVariableRedundantNullAssignment(local, reference); >Index: compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java,v >retrieving revision 1.40 >diff -u -r1.40 FlowInfo.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java 11 Feb 2010 01:32:26 -0000 1.40 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java 24 Feb 2010 10:08:46 -0000 >@@ -457,4 +457,20 @@ > * @return a flow info carrying this unconditional flow info > */ > abstract public UnconditionalFlowInfo unconditionalInitsWithoutSideEffect(); >+ >+/** >+ * Tell the flowInfo that a local variable got marked as non null or null >+ * due to comparison with null inside an assert expression. >+ * This is to prevent over-aggressive code generation for subsequent if statements >+ * where this variable is being checked against null >+ */ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448 >+abstract public void markedAsNullOrNonNullInAssertExpression(LocalVariableBinding local); >+ >+/** >+ * Returns true if the local variable being checked for was marked as null or not null >+ * inside an assert expression due to comparison against null. >+ */ >+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448 >+abstract public boolean isMarkedAsNullOrNonNullInAssertExpression(LocalVariableBinding local); > } >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.48 >diff -u -r1.48 LoopingFlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 23 Feb 2010 18:27:09 -0000 1.48 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 24 Feb 2010 10:08:46 -0000 >@@ -473,24 +473,32 @@ > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); > } >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ } > } else { > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNonNullComparedToNull(local, reference); > } >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ } > } > } else if (flowInfo.isDefinitelyNull(local)) { > if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) { > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > } >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ } > } else { > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ } > } > } else if (this.upstreamNullFlowInfo.isDefinitelyNonNull(local) && !flowInfo.isPotentiallyNull(local)) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=291418 > flowInfo.markAsDefinitelyNonNull(local); >@@ -525,7 +533,9 @@ > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > } >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ } > return; > case FlowContext.IN_COMPARISON_NON_NULL: > if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >@@ -535,7 +545,9 @@ > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ } > return; > case FlowContext.IN_ASSIGNMENT: > scope.problemReporter().localVariableRedundantNullAssignment(local, reference); >Index: compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java,v >retrieving revision 1.64 >diff -u -r1.64 UnconditionalFlowInfo.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 7 Mar 2009 00:59:06 -0000 1.64 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 24 Feb 2010 10:08:48 -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 >@@ -84,6 +84,7 @@ > > // Constants > public static final int BitCacheSize = 64; // 64 bits in a long. >+ public int nullStatusChangedInAssert[]; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448 > > public FlowInfo addInitializationsFrom(FlowInfo inits) { > if (this == DEAD_END) >@@ -283,6 +284,7 @@ > } > } > } >+ combineNullStatusChangeInAssertInfo(otherInits); > return this; > } > >@@ -490,6 +492,7 @@ > } > } > } >+ combineNullStatusChangeInAssertInfo(otherInits); > if (thisHasNulls) { > this.tagBits |= NULL_FLAG_MASK; > } >@@ -621,6 +624,7 @@ > } > } > } >+ copy.nullStatusChangedInAssert = this.nullStatusChangedInAssert; > return copy; > } > >@@ -1571,6 +1575,7 @@ > } > } > } >+ combineNullStatusChangeInAssertInfo(otherInits); > if (thisHasNulls) { > this.tagBits |= NULL_FLAG_MASK; > } >@@ -1732,6 +1737,7 @@ > copy.nullBit3 = this.nullBit3 & mask; > copy.nullBit4 = this.nullBit4 & mask; > } >+ copy.nullStatusChangedInAssert = this.nullStatusChangedInAssert; > // use extra vector > if (this.extra == null) { > return copy; // if vector not yet allocated, then not initialized >@@ -1774,5 +1780,60 @@ > public UnconditionalFlowInfo unconditionalInitsWithoutSideEffect() { > return this; > } >+ >+public void markedAsNullOrNonNullInAssertExpression(LocalVariableBinding local) { >+ int position = local.id + this.maxFieldCount; >+ int oldLength; >+ if (this.nullStatusChangedInAssert == null) { >+ this.nullStatusChangedInAssert = new int[position + 1]; >+ } >+ else { >+ if(position >= (oldLength = this.nullStatusChangedInAssert.length)) { >+ System.arraycopy(this.nullStatusChangedInAssert, 0, (this.nullStatusChangedInAssert = new int[position + 1]), 0, oldLength); >+ } >+ } >+ this.nullStatusChangedInAssert[position] = 1; >+} >+ >+public boolean isMarkedAsNullOrNonNullInAssertExpression(LocalVariableBinding local) { >+ int position = local.id + this.maxFieldCount; >+ if(this.nullStatusChangedInAssert == null || position >= this.nullStatusChangedInAssert.length) { >+ return false; >+ } >+ if(this.nullStatusChangedInAssert[position] == 1) { >+ return true; >+ } >+ return false; >+} >+ >+/** >+ * Combine the null status changes in assert expressions info >+ * @param otherInits >+ */ >+// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448 >+private void combineNullStatusChangeInAssertInfo(UnconditionalFlowInfo otherInits) { >+ if (this.nullStatusChangedInAssert != null || otherInits.nullStatusChangedInAssert != null) { >+ int mergedLength, length; >+ if (this.nullStatusChangedInAssert != null) { >+ if (otherInits.nullStatusChangedInAssert != null) { >+ if(otherInits.nullStatusChangedInAssert.length > this.nullStatusChangedInAssert.length) { >+ mergedLength = otherInits.nullStatusChangedInAssert.length; >+ length = this.nullStatusChangedInAssert.length; >+ System.arraycopy(this.nullStatusChangedInAssert, 0, (this.nullStatusChangedInAssert = new int[mergedLength]), 0, length); >+ for(int i = 0; i < length; i ++) { >+ this.nullStatusChangedInAssert[i] |= otherInits.nullStatusChangedInAssert[i]; >+ } >+ System.arraycopy(otherInits.nullStatusChangedInAssert, length, this.nullStatusChangedInAssert, length, mergedLength - length); >+ } else { >+ for(int i = 0; i < otherInits.nullStatusChangedInAssert.length; i ++) { >+ this.nullStatusChangedInAssert[i] |= otherInits.nullStatusChangedInAssert[i]; >+ } >+ } >+ } >+ } else if (otherInits.nullStatusChangedInAssert != null) { >+ this.nullStatusChangedInAssert = otherInits.nullStatusChangedInAssert; >+ } >+ } >+} > } > >#P org.eclipse.jdt.core.tests >Index: Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/ConformTest.java >=================================================================== >RCS file: /home/cvs/numbat/org.eclipse.jdt.core.tests/Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/ConformTest.java,v >retrieving revision 1.153 >diff -u -r1.153 ConformTest.java >--- Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/ConformTest.java 21 Jan 2010 16:48:36 -0000 1.153 >+++ Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/ConformTest.java 24 Feb 2010 10:09:00 -0000 >@@ -6766,6 +6766,784 @@ > }, > "SUCCESS"); > } >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448 >+// To check that code gen is not optimized for an if statement >+// where a local variable's definite nullness or otherwise is known because of >+// an earlier assert expression >+public void testBug303448a() throws Exception { >+ if (this.complianceLevel >= ClassFileConstants.JDK1_4) { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public void foo(String[] args, Object foo) {\n" + >+ " assert foo != null;" + >+ " if (foo!= null) {\n" + >+ " System.out.println(\"foo is not null\");\n" + >+ " } else {\n" + >+ " System.out.println(\"foo is null\");\n" + >+ " }\n" + >+ " }\n" + >+ "}\n", >+ }, >+ "", >+ null, >+ true, >+ null, >+ getCompilerOptions(), >+ null); // custom requestor >+ >+ String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_5 ? >+ " // Method descriptor #49 ([Ljava/lang/String;Ljava/lang/Object;)V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public void foo(java.lang.String[] args, java.lang.Object foo);\n" + >+ " 0 getstatic X.$assertionsDisabled : boolean [38]\n" + >+ " 3 ifne 18\n" + >+ " 6 aload_2 [foo]\n" + >+ " 7 ifnonnull 18\n" + >+ " 10 new java.lang.AssertionError [50]\n" + >+ " 13 dup\n" + >+ " 14 invokespecial java.lang.AssertionError() [52]\n" + >+ " 17 athrow\n" + >+ " 18 aload_2 [foo]\n" + >+ " 19 ifnull 33\n" + >+ " 22 getstatic java.lang.System.out : java.io.PrintStream [53]\n" + >+ " 25 ldc <String \"foo is not null\"> [59]\n" + >+ " 27 invokevirtual java.io.PrintStream.println(java.lang.String) : void [61]\n" + >+ " 30 goto 41\n" + >+ " 33 getstatic java.lang.System.out : java.io.PrintStream [53]\n" + >+ " 36 ldc <String \"foo is null\"> [66]\n" + >+ " 38 invokevirtual java.io.PrintStream.println(java.lang.String) : void [61]\n" + >+ " 41 return\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 22, line: 4]\n" + >+ " [pc: 33, line: 6]\n" + >+ " [pc: 41, line: 8]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 42] local: this index: 0 type: X\n" + >+ " [pc: 0, pc: 42] local: args index: 1 type: java.lang.String[]\n" + >+ " [pc: 0, pc: 42] local: foo index: 2 type: java.lang.Object\n" >+ : this.complianceLevel < ClassFileConstants.JDK1_6 ? >+ " // Method descriptor #26 ([Ljava/lang/String;Ljava/lang/Object;)V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public void foo(java.lang.String[] args, java.lang.Object foo);\n" + >+ " 0 getstatic X.$assertionsDisabled : boolean [16]\n" + >+ " 3 ifne 18\n" + >+ " 6 aload_2 [foo]\n" + >+ " 7 ifnonnull 18\n" + >+ " 10 new java.lang.AssertionError [27]\n" + >+ " 13 dup\n" + >+ " 14 invokespecial java.lang.AssertionError() [29]\n" + >+ " 17 athrow\n" + >+ " 18 aload_2 [foo]\n" + >+ " 19 ifnull 33\n" + >+ " 22 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 25 ldc <String \"foo is not null\"> [36]\n" + >+ " 27 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 30 goto 41\n" + >+ " 33 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 36 ldc <String \"foo is null\"> [44]\n" + >+ " 38 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 41 return\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 22, line: 4]\n" + >+ " [pc: 33, line: 6]\n" + >+ " [pc: 41, line: 8]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 42] local: this index: 0 type: X\n" + >+ " [pc: 0, pc: 42] local: args index: 1 type: java.lang.String[]\n" + >+ " [pc: 0, pc: 42] local: foo index: 2 type: java.lang.Object\n" >+ : " // Method descriptor #27 ([Ljava/lang/String;Ljava/lang/Object;)V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public void foo(java.lang.String[] args, java.lang.Object foo);\n" + >+ " 0 getstatic X.$assertionsDisabled : boolean [16]\n" + >+ " 3 ifne 18\n" + >+ " 6 aload_2 [foo]\n" + >+ " 7 ifnonnull 18\n" + >+ " 10 new java.lang.AssertionError [28]\n" + >+ " 13 dup\n" + >+ " 14 invokespecial java.lang.AssertionError() [30]\n" + >+ " 17 athrow\n" + >+ " 18 aload_2 [foo]\n" + >+ " 19 ifnull 33\n" + >+ " 22 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + >+ " 25 ldc <String \"foo is not null\"> [37]\n" + >+ " 27 invokevirtual java.io.PrintStream.println(java.lang.String) : void [39]\n" + >+ " 30 goto 41\n" + >+ " 33 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + >+ " 36 ldc <String \"foo is null\"> [45]\n" + >+ " 38 invokevirtual java.io.PrintStream.println(java.lang.String) : void [39]\n" + >+ " 41 return\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 22, line: 4]\n" + >+ " [pc: 33, line: 6]\n" + >+ " [pc: 41, line: 8]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 42] local: this index: 0 type: X\n" + >+ " [pc: 0, pc: 42] local: args index: 1 type: java.lang.String[]\n" + >+ " [pc: 0, pc: 42] local: foo index: 2 type: java.lang.Object\n" + >+ " Stack map table: number of frames 3\n" + >+ " [pc: 18, same]\n" + >+ " [pc: 33, same]\n" + >+ " [pc: 41, same]\n" ; >+ >+ File f = new File(OUTPUT_DIR + File.separator + "X.class"); >+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); >+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); >+ String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); >+ int index = result.indexOf(expectedOutput); >+ if (index == -1 || expectedOutput.length() == 0) { >+ System.out.println(Util.displayString(result, 3)); >+ } >+ if (index == -1) { >+ assertEquals("Wrong contents", expectedOutput, result); >+ } >+ } >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448 >+// To check that code gen is not optimized for an if statement >+// where a local variable's definite nullness or otherwise is known because of >+// an earlier assert expression >+public void testBug303448b() throws Exception { >+ if (this.complianceLevel >= ClassFileConstants.JDK1_4) { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public void foo() {\n" + >+ " Object foo = null;\n" + >+ " Object foo2 = null;\n" + >+ " assert (foo != null && foo2 != null);\n" + >+ " if (foo != null) {\n" + >+ " System.out.println(\"foo is not null\");\n" + >+ " } else {\n" + >+ " System.out.println(\"foo is null\");\n" + >+ " }\n" + >+ " if (foo2 != null) {\n" + >+ " System.out.println(\"foo2 is not null\");\n" + >+ " } else {\n" + >+ " System.out.println(\"foo2 is null\");\n" + >+ " }\n" + >+ " }\n" + >+ "}\n", >+ }, >+ "", >+ null, >+ true, >+ null, >+ getCompilerOptions(), >+ null); // custom requestor >+ >+ String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_5? >+ " // Method descriptor #11 ()V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public void foo();\n" + >+ " 0 aconst_null\n" + >+ " 1 astore_1 [foo]\n" + >+ " 2 aconst_null\n" + >+ " 3 astore_2 [foo2]\n" + >+ " 4 getstatic X.$assertionsDisabled : boolean [38]\n" + >+ " 7 ifne 26\n" + >+ " 10 aload_1 [foo]\n" + >+ " 11 ifnull 18\n" + >+ " 14 aload_2 [foo2]\n" + >+ " 15 ifnonnull 26\n" + >+ " 18 new java.lang.AssertionError [49]\n" + >+ " 21 dup\n" + >+ " 22 invokespecial java.lang.AssertionError() [51]\n" + >+ " 25 athrow\n" + >+ " 26 aload_1 [foo]\n" + >+ " 27 ifnull 41\n" + >+ " 30 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + >+ " 33 ldc <String \"foo is not null\"> [58]\n" + >+ " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + >+ " 38 goto 49\n" + >+ " 41 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + >+ " 44 ldc <String \"foo is null\"> [65]\n" + >+ " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + >+ " 49 aload_2 [foo2]\n" + >+ " 50 ifnull 64\n" + >+ " 53 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + >+ " 56 ldc <String \"foo2 is not null\"> [67]\n" + >+ " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + >+ " 61 goto 72\n" + >+ " 64 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + >+ " 67 ldc <String \"foo2 is null\"> [69]\n" + >+ " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + >+ " 72 return\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 2, line: 4]\n" + >+ " [pc: 4, line: 5]\n" + >+ " [pc: 26, line: 6]\n" + >+ " [pc: 30, line: 7]\n" + >+ " [pc: 41, line: 9]\n" + >+ " [pc: 49, line: 11]\n" + >+ " [pc: 53, line: 12]\n" + >+ " [pc: 64, line: 14]\n" + >+ " [pc: 72, line: 16]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 73] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + >+ " [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n" >+ : this.complianceLevel < ClassFileConstants.JDK1_6? >+ " // Method descriptor #8 ()V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public void foo();\n" + >+ " 0 aconst_null\n" + >+ " 1 astore_1 [foo]\n" + >+ " 2 aconst_null\n" + >+ " 3 astore_2 [foo2]\n" + >+ " 4 getstatic X.$assertionsDisabled : boolean [16]\n" + >+ " 7 ifne 26\n" + >+ " 10 aload_1 [foo]\n" + >+ " 11 ifnull 18\n" + >+ " 14 aload_2 [foo2]\n" + >+ " 15 ifnonnull 26\n" + >+ " 18 new java.lang.AssertionError [26]\n" + >+ " 21 dup\n" + >+ " 22 invokespecial java.lang.AssertionError() [28]\n" + >+ " 25 athrow\n" + >+ " 26 aload_1 [foo]\n" + >+ " 27 ifnull 41\n" + >+ " 30 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + >+ " 33 ldc <String \"foo is not null\"> [35]\n" + >+ " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + >+ " 38 goto 49\n" + >+ " 41 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + >+ " 44 ldc <String \"foo is null\"> [43]\n" + >+ " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + >+ " 49 aload_2 [foo2]\n" + >+ " 50 ifnull 64\n" + >+ " 53 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + >+ " 56 ldc <String \"foo2 is not null\"> [45]\n" + >+ " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + >+ " 61 goto 72\n" + >+ " 64 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + >+ " 67 ldc <String \"foo2 is null\"> [47]\n" + >+ " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + >+ " 72 return\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 2, line: 4]\n" + >+ " [pc: 4, line: 5]\n" + >+ " [pc: 26, line: 6]\n" + >+ " [pc: 30, line: 7]\n" + >+ " [pc: 41, line: 9]\n" + >+ " [pc: 49, line: 11]\n" + >+ " [pc: 53, line: 12]\n" + >+ " [pc: 64, line: 14]\n" + >+ " [pc: 72, line: 16]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 73] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + >+ " [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n" >+ : " // Method descriptor #8 ()V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public void foo();\n" + >+ " 0 aconst_null\n" + >+ " 1 astore_1 [foo]\n" + >+ " 2 aconst_null\n" + >+ " 3 astore_2 [foo2]\n" + >+ " 4 getstatic X.$assertionsDisabled : boolean [16]\n" + >+ " 7 ifne 26\n" + >+ " 10 aload_1 [foo]\n" + >+ " 11 ifnull 18\n" + >+ " 14 aload_2 [foo2]\n" + >+ " 15 ifnonnull 26\n" + >+ " 18 new java.lang.AssertionError [27]\n" + >+ " 21 dup\n" + >+ " 22 invokespecial java.lang.AssertionError() [29]\n" + >+ " 25 athrow\n" + >+ " 26 aload_1 [foo]\n" + >+ " 27 ifnull 41\n" + >+ " 30 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 33 ldc <String \"foo is not null\"> [36]\n" + >+ " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 38 goto 49\n" + >+ " 41 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 44 ldc <String \"foo is null\"> [44]\n" + >+ " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 49 aload_2 [foo2]\n" + >+ " 50 ifnull 64\n" + >+ " 53 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 56 ldc <String \"foo2 is not null\"> [46]\n" + >+ " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 61 goto 72\n" + >+ " 64 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 67 ldc <String \"foo2 is null\"> [48]\n" + >+ " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 72 return\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 2, line: 4]\n" + >+ " [pc: 4, line: 5]\n" + >+ " [pc: 26, line: 6]\n" + >+ " [pc: 30, line: 7]\n" + >+ " [pc: 41, line: 9]\n" + >+ " [pc: 49, line: 11]\n" + >+ " [pc: 53, line: 12]\n" + >+ " [pc: 64, line: 14]\n" + >+ " [pc: 72, line: 16]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 73] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + >+ " [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n" + >+ " Stack map table: number of frames 6\n" + >+ " [pc: 18, append: {java.lang.Object, java.lang.Object}]\n" + >+ " [pc: 26, same]\n" + >+ " [pc: 41, same]\n" + >+ " [pc: 49, same]\n" + >+ " [pc: 64, same]\n" + >+ " [pc: 72, same]\n"; >+ >+ File f = new File(OUTPUT_DIR + File.separator + "X.class"); >+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); >+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); >+ String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); >+ int index = result.indexOf(expectedOutput); >+ if (index == -1 || expectedOutput.length() == 0) { >+ System.out.println(Util.displayString(result, 3)); >+ } >+ if (index == -1) { >+ assertEquals("Wrong contents", expectedOutput, result); >+ } >+ } >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448 >+// To check that code gen is not optimized for an if statement >+// where a local variable's definite nullness or otherwise is known because of >+// an earlier assert expression (inside looping context) >+public void testBug303448c() throws Exception { >+ if (this.complianceLevel >= ClassFileConstants.JDK1_4) { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public void foo() {\n" + >+ " Object foo = null;\n" + >+ " Object foo2 = null;\n" + >+ " while(true){\n" + >+ " assert (foo != null && foo2 != null);\n" + >+ " if (foo != null) {\n" + >+ " System.out.println(\"foo is not null\");\n" + >+ " } else {\n" + >+ " System.out.println(\"foo is null\");\n" + >+ " }\n" + >+ " if (foo2 != null) {\n" + >+ " System.out.println(\"foo2 is not null\");\n" + >+ " } else {\n" + >+ " System.out.println(\"foo2 is null\");\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ "}\n", >+ }, >+ "", >+ null, >+ true, >+ null, >+ getCompilerOptions(), >+ null); // custom requestor >+ >+ String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_5? >+ " // Method descriptor #11 ()V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public void foo();\n" + >+ " 0 aconst_null\n" + >+ " 1 astore_1 [foo]\n" + >+ " 2 aconst_null\n" + >+ " 3 astore_2 [foo2]\n" + >+ " 4 getstatic X.$assertionsDisabled : boolean [38]\n" + >+ " 7 ifne 26\n" + >+ " 10 aload_1 [foo]\n" + >+ " 11 ifnull 18\n" + >+ " 14 aload_2 [foo2]\n" + >+ " 15 ifnonnull 26\n" + >+ " 18 new java.lang.AssertionError [49]\n" + >+ " 21 dup\n" + >+ " 22 invokespecial java.lang.AssertionError() [51]\n" + >+ " 25 athrow\n" + >+ " 26 aload_1 [foo]\n" + >+ " 27 ifnull 41\n" + >+ " 30 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + >+ " 33 ldc <String \"foo is not null\"> [58]\n" + >+ " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + >+ " 38 goto 49\n" + >+ " 41 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + >+ " 44 ldc <String \"foo is null\"> [65]\n" + >+ " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + >+ " 49 aload_2 [foo2]\n" + >+ " 50 ifnull 64\n" + >+ " 53 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + >+ " 56 ldc <String \"foo2 is not null\"> [67]\n" + >+ " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + >+ " 61 goto 4\n" + >+ " 64 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + >+ " 67 ldc <String \"foo2 is null\"> [69]\n" + >+ " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + >+ " 72 goto 4\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 2, line: 4]\n" + >+ " [pc: 4, line: 6]\n" + >+ " [pc: 26, line: 7]\n" + >+ " [pc: 30, line: 8]\n" + >+ " [pc: 41, line: 10]\n" + >+ " [pc: 49, line: 12]\n" + >+ " [pc: 53, line: 13]\n" + >+ " [pc: 64, line: 15]\n" + >+ " [pc: 72, line: 5]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 75] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 75] local: foo index: 1 type: java.lang.Object\n" + >+ " [pc: 4, pc: 75] local: foo2 index: 2 type: java.lang.Object\n" >+ : this.complianceLevel < ClassFileConstants.JDK1_6? >+ " // Method descriptor #8 ()V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public void foo();\n" + >+ " 0 aconst_null\n" + >+ " 1 astore_1 [foo]\n" + >+ " 2 aconst_null\n" + >+ " 3 astore_2 [foo2]\n" + >+ " 4 getstatic X.$assertionsDisabled : boolean [16]\n" + >+ " 7 ifne 26\n" + >+ " 10 aload_1 [foo]\n" + >+ " 11 ifnull 18\n" + >+ " 14 aload_2 [foo2]\n" + >+ " 15 ifnonnull 26\n" + >+ " 18 new java.lang.AssertionError [26]\n" + >+ " 21 dup\n" + >+ " 22 invokespecial java.lang.AssertionError() [28]\n" + >+ " 25 athrow\n" + >+ " 26 aload_1 [foo]\n" + >+ " 27 ifnull 41\n" + >+ " 30 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + >+ " 33 ldc <String \"foo is not null\"> [35]\n" + >+ " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + >+ " 38 goto 49\n" + >+ " 41 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + >+ " 44 ldc <String \"foo is null\"> [43]\n" + >+ " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + >+ " 49 aload_2 [foo2]\n" + >+ " 50 ifnull 64\n" + >+ " 53 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + >+ " 56 ldc <String \"foo2 is not null\"> [45]\n" + >+ " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + >+ " 61 goto 4\n" + >+ " 64 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + >+ " 67 ldc <String \"foo2 is null\"> [47]\n" + >+ " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + >+ " 72 goto 4\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 2, line: 4]\n" + >+ " [pc: 4, line: 6]\n" + >+ " [pc: 26, line: 7]\n" + >+ " [pc: 30, line: 8]\n" + >+ " [pc: 41, line: 10]\n" + >+ " [pc: 49, line: 12]\n" + >+ " [pc: 53, line: 13]\n" + >+ " [pc: 64, line: 15]\n" + >+ " [pc: 72, line: 5]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 75] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 75] local: foo index: 1 type: java.lang.Object\n" + >+ " [pc: 4, pc: 75] local: foo2 index: 2 type: java.lang.Object\n" >+ : " // Method descriptor #8 ()V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public void foo();\n" + >+ " 0 aconst_null\n" + >+ " 1 astore_1 [foo]\n" + >+ " 2 aconst_null\n" + >+ " 3 astore_2 [foo2]\n" + >+ " 4 getstatic X.$assertionsDisabled : boolean [16]\n" + >+ " 7 ifne 26\n" + >+ " 10 aload_1 [foo]\n" + >+ " 11 ifnull 18\n" + >+ " 14 aload_2 [foo2]\n" + >+ " 15 ifnonnull 26\n" + >+ " 18 new java.lang.AssertionError [27]\n" + >+ " 21 dup\n" + >+ " 22 invokespecial java.lang.AssertionError() [29]\n" + >+ " 25 athrow\n" + >+ " 26 aload_1 [foo]\n" + >+ " 27 ifnull 41\n" + >+ " 30 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 33 ldc <String \"foo is not null\"> [36]\n" + >+ " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 38 goto 49\n" + >+ " 41 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 44 ldc <String \"foo is null\"> [44]\n" + >+ " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 49 aload_2 [foo2]\n" + >+ " 50 ifnull 64\n" + >+ " 53 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 56 ldc <String \"foo2 is not null\"> [46]\n" + >+ " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 61 goto 4\n" + >+ " 64 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 67 ldc <String \"foo2 is null\"> [48]\n" + >+ " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 72 goto 4\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 2, line: 4]\n" + >+ " [pc: 4, line: 6]\n" + >+ " [pc: 26, line: 7]\n" + >+ " [pc: 30, line: 8]\n" + >+ " [pc: 41, line: 10]\n" + >+ " [pc: 49, line: 12]\n" + >+ " [pc: 53, line: 13]\n" + >+ " [pc: 64, line: 15]\n" + >+ " [pc: 72, line: 5]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 75] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 75] local: foo index: 1 type: java.lang.Object\n" + >+ " [pc: 4, pc: 75] local: foo2 index: 2 type: java.lang.Object\n" + >+ " Stack map table: number of frames 7\n" + >+ " [pc: 4, append: {java.lang.Object, java.lang.Object}]\n" + >+ " [pc: 18, same]\n" + >+ " [pc: 26, same]\n" + >+ " [pc: 41, same]\n" + >+ " [pc: 49, same]\n" + >+ " [pc: 64, same]\n" + >+ " [pc: 72, same]\n"; >+ >+ File f = new File(OUTPUT_DIR + File.separator + "X.class"); >+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); >+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); >+ String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); >+ int index = result.indexOf(expectedOutput); >+ if (index == -1 || expectedOutput.length() == 0) { >+ System.out.println(Util.displayString(result, 3)); >+ } >+ if (index == -1) { >+ assertEquals("Wrong contents", expectedOutput, result); >+ } >+ } >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448 >+// To check that code gen is not optimized for an if statement >+// where a local variable's definite nullness or otherwise is known because of >+// an earlier assert expression (inside finally context) >+public void testBug303448d() throws Exception { >+ if (this.complianceLevel >= ClassFileConstants.JDK1_4) { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public void foo() {\n" + >+ " Object foo = null;\n" + >+ " Object foo2 = null;\n" + >+ " try {} \n" + >+ " finally {\n" + >+ " assert (foo != null && foo2 != null);\n" + >+ " if (foo != null) {\n" + >+ " System.out.println(\"foo is not null\");\n" + >+ " } else {\n" + >+ " System.out.println(\"foo is null\");\n" + >+ " }\n" + >+ " if (foo2 != null) {\n" + >+ " System.out.println(\"foo2 is not null\");\n" + >+ " } else {\n" + >+ " System.out.println(\"foo2 is null\");\n" + >+ " }\n" + >+ " }\n" + >+ " }\n" + >+ "}\n", >+ }, >+ "", >+ null, >+ true, >+ null, >+ getCompilerOptions(), >+ null); // custom requestor >+ >+ String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_5? >+ " // Method descriptor #11 ()V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public void foo();\n" + >+ " 0 aconst_null\n" + >+ " 1 astore_1 [foo]\n" + >+ " 2 aconst_null\n" + >+ " 3 astore_2 [foo2]\n" + >+ " 4 getstatic X.$assertionsDisabled : boolean [38]\n" + >+ " 7 ifne 26\n" + >+ " 10 aload_1 [foo]\n" + >+ " 11 ifnull 18\n" + >+ " 14 aload_2 [foo2]\n" + >+ " 15 ifnonnull 26\n" + >+ " 18 new java.lang.AssertionError [49]\n" + >+ " 21 dup\n" + >+ " 22 invokespecial java.lang.AssertionError() [51]\n" + >+ " 25 athrow\n" + >+ " 26 aload_1 [foo]\n" + >+ " 27 ifnull 41\n" + >+ " 30 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + >+ " 33 ldc <String \"foo is not null\"> [58]\n" + >+ " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + >+ " 38 goto 49\n" + >+ " 41 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + >+ " 44 ldc <String \"foo is null\"> [65]\n" + >+ " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + >+ " 49 aload_2 [foo2]\n" + >+ " 50 ifnull 64\n" + >+ " 53 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + >+ " 56 ldc <String \"foo2 is not null\"> [67]\n" + >+ " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + >+ " 61 goto 72\n" + >+ " 64 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + >+ " 67 ldc <String \"foo2 is null\"> [69]\n" + >+ " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + >+ " 72 return\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 2, line: 4]\n" + >+ " [pc: 4, line: 7]\n" + >+ " [pc: 26, line: 8]\n" + >+ " [pc: 30, line: 9]\n" + >+ " [pc: 41, line: 11]\n" + >+ " [pc: 49, line: 13]\n" + >+ " [pc: 53, line: 14]\n" + >+ " [pc: 64, line: 16]\n" + >+ " [pc: 72, line: 19]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 73] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + >+ " [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n" >+ : this.complianceLevel < ClassFileConstants.JDK1_6? >+ " // Method descriptor #8 ()V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public void foo();\n" + >+ " 0 aconst_null\n" + >+ " 1 astore_1 [foo]\n" + >+ " 2 aconst_null\n" + >+ " 3 astore_2 [foo2]\n" + >+ " 4 getstatic X.$assertionsDisabled : boolean [16]\n" + >+ " 7 ifne 26\n" + >+ " 10 aload_1 [foo]\n" + >+ " 11 ifnull 18\n" + >+ " 14 aload_2 [foo2]\n" + >+ " 15 ifnonnull 26\n" + >+ " 18 new java.lang.AssertionError [26]\n" + >+ " 21 dup\n" + >+ " 22 invokespecial java.lang.AssertionError() [28]\n" + >+ " 25 athrow\n" + >+ " 26 aload_1 [foo]\n" + >+ " 27 ifnull 41\n" + >+ " 30 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + >+ " 33 ldc <String \"foo is not null\"> [35]\n" + >+ " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + >+ " 38 goto 49\n" + >+ " 41 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + >+ " 44 ldc <String \"foo is null\"> [43]\n" + >+ " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + >+ " 49 aload_2 [foo2]\n" + >+ " 50 ifnull 64\n" + >+ " 53 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + >+ " 56 ldc <String \"foo2 is not null\"> [45]\n" + >+ " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + >+ " 61 goto 72\n" + >+ " 64 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + >+ " 67 ldc <String \"foo2 is null\"> [47]\n" + >+ " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + >+ " 72 return\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 2, line: 4]\n" + >+ " [pc: 4, line: 7]\n" + >+ " [pc: 26, line: 8]\n" + >+ " [pc: 30, line: 9]\n" + >+ " [pc: 41, line: 11]\n" + >+ " [pc: 49, line: 13]\n" + >+ " [pc: 53, line: 14]\n" + >+ " [pc: 64, line: 16]\n" + >+ " [pc: 72, line: 19]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 73] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + >+ " [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n" >+ : " // Method descriptor #8 ()V\n" + >+ " // Stack: 2, Locals: 3\n" + >+ " public void foo();\n" + >+ " 0 aconst_null\n" + >+ " 1 astore_1 [foo]\n" + >+ " 2 aconst_null\n" + >+ " 3 astore_2 [foo2]\n" + >+ " 4 getstatic X.$assertionsDisabled : boolean [16]\n" + >+ " 7 ifne 26\n" + >+ " 10 aload_1 [foo]\n" + >+ " 11 ifnull 18\n" + >+ " 14 aload_2 [foo2]\n" + >+ " 15 ifnonnull 26\n" + >+ " 18 new java.lang.AssertionError [27]\n" + >+ " 21 dup\n" + >+ " 22 invokespecial java.lang.AssertionError() [29]\n" + >+ " 25 athrow\n" + >+ " 26 aload_1 [foo]\n" + >+ " 27 ifnull 41\n" + >+ " 30 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 33 ldc <String \"foo is not null\"> [36]\n" + >+ " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 38 goto 49\n" + >+ " 41 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 44 ldc <String \"foo is null\"> [44]\n" + >+ " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 49 aload_2 [foo2]\n" + >+ " 50 ifnull 64\n" + >+ " 53 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 56 ldc <String \"foo2 is not null\"> [46]\n" + >+ " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 61 goto 72\n" + >+ " 64 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + >+ " 67 ldc <String \"foo2 is null\"> [48]\n" + >+ " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + >+ " 72 return\n" + >+ " Line numbers:\n" + >+ " [pc: 0, line: 3]\n" + >+ " [pc: 2, line: 4]\n" + >+ " [pc: 4, line: 7]\n" + >+ " [pc: 26, line: 8]\n" + >+ " [pc: 30, line: 9]\n" + >+ " [pc: 41, line: 11]\n" + >+ " [pc: 49, line: 13]\n" + >+ " [pc: 53, line: 14]\n" + >+ " [pc: 64, line: 16]\n" + >+ " [pc: 72, line: 19]\n" + >+ " Local variable table:\n" + >+ " [pc: 0, pc: 73] local: this index: 0 type: X\n" + >+ " [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + >+ " [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n" + >+ " Stack map table: number of frames 6\n" + >+ " [pc: 18, append: {java.lang.Object, java.lang.Object}]\n" + >+ " [pc: 26, same]\n" + >+ " [pc: 41, same]\n" + >+ " [pc: 49, same]\n" + >+ " [pc: 64, same]\n" + >+ " [pc: 72, same]\n"; >+ >+ File f = new File(OUTPUT_DIR + File.separator + "X.class"); >+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); >+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); >+ String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); >+ int index = result.indexOf(expectedOutput); >+ if (index == -1 || expectedOutput.length() == 0) { >+ System.out.println(Util.displayString(result, 3)); >+ } >+ if (index == -1) { >+ assertEquals("Wrong contents", expectedOutput, result); >+ } >+ } >+} >+ > public static Class testClass() { > return ConformTest.class; > } >#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.90 >diff -u -r1.90 NullReferenceTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 23 Feb 2010 18:27:08 -0000 1.90 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 24 Feb 2010 10:09:14 -0000 >@@ -8232,12 +8232,7 @@ > " ^^\n" + > "Null comparison always yields false: The variable o1 cannot be null at this location\n" + > "----------\n" + >- "2. WARNING in X.java (at line 4)\n" + >- " if (o1 == null) { };\n" + >- " ^^^\n" + >- "Dead code\n" + >- "----------\n" + >- "3. ERROR in X.java (at line 5)\n" + >+ "2. ERROR in X.java (at line 5)\n" + > " if (o2 == null) { };\n" + > " ^^\n" + > "Redundant null check: The variable o2 can only be null at this location\n" + >@@ -8286,11 +8281,6 @@ > " if (o == null) { };\n" + > " ^\n" + > "Null comparison always yields false: The variable o cannot be null at this location\n" + >- "----------\n" + >- "2. WARNING in X.java (at line 4)\n" + >- " if (o == null) { };\n" + >- " ^^^\n" + >- "Dead code\n" + > "----------\n", > JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); > } >@@ -8315,11 +8305,6 @@ > " if (o == null) { };\n" + > " ^\n" + > "Null comparison always yields false: The variable o cannot be null at this location\n" + >- "----------\n" + >- "2. WARNING in X.java (at line 5)\n" + >- " if (o == null) { };\n" + >- " ^^^\n" + >- "Dead code\n" + > "----------\n", > JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); > } >@@ -8354,31 +8339,21 @@ > " if (foo == null) {}\n" + > " ^^^\n" + > "Null comparison always yields false: The variable foo cannot be null at this location\n" + >- "----------\n" + >- "2. WARNING in X.java (at line 5)\n" + >- " if (foo == null) {}\n" + >- " ^^\n" + >- "Dead code\n" + >- "----------\n" + >- "3. ERROR in X.java (at line 8)\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 8)\n" + > " if (foo2 == null) {}\n" + > " ^^^^\n" + > "Redundant null check: The variable foo2 can only be null at this location\n" + > "----------\n" + >- "4. ERROR in X.java (at line 11)\n" + >+ "3. ERROR in X.java (at line 11)\n" + > " if (bar == null) {}\n" + > " ^^^\n" + > "Redundant null check: The variable bar can only be null at this location\n" + > "----------\n" + >- "5. ERROR in X.java (at line 14)\n" + >+ "4. ERROR in X.java (at line 14)\n" + > " if (bar2 == null) {}\n" + > " ^^^^\n" + > "Null comparison always yields false: The variable bar2 cannot be null at this location\n" + >- "----------\n" + >- "6. WARNING in X.java (at line 14)\n" + >- " if (bar2 == null) {}\n" + >- " ^^\n" + >- "Dead code\n" + > "----------\n", > JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); > } >@@ -8454,30 +8429,20 @@ > " ^^^\n" + > "Null comparison always yields false: The variable foo cannot be null at this location\n" + > "----------\n" + >- "2. WARNING in X.java (at line 9)\n" + >- " if (foo == null) {}\n" + >- " ^^\n" + >- "Dead code\n" + >- "----------\n" + >- "3. ERROR in X.java (at line 11)\n" + >+ "2. ERROR in X.java (at line 11)\n" + > " if (foo2 == null) {}\n" + > " ^^^^\n" + > "Redundant null check: The variable foo2 can only be null at this location\n" + > "----------\n" + >- "4. ERROR in X.java (at line 13)\n" + >+ "3. ERROR in X.java (at line 13)\n" + > " if (bar == null) {}\n" + > " ^^^\n" + > "Redundant null check: The variable bar can only be null at this location\n" + > "----------\n" + >- "5. ERROR in X.java (at line 15)\n" + >+ "4. ERROR in X.java (at line 15)\n" + > " if (bar2 == null) {}\n" + > " ^^^^\n" + > "Null comparison always yields false: The variable bar2 cannot be null at this location\n" + >- "----------\n" + >- "6. WARNING in X.java (at line 15)\n" + >- " if (bar2 == null) {}\n" + >- " ^^\n" + >- "Dead code\n" + > "----------\n", > JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); > } >@@ -8515,30 +8480,20 @@ > " ^^^\n" + > "Null comparison always yields false: The variable foo cannot be null at this location\n" + > "----------\n" + >- "2. WARNING in X.java (at line 6)\n" + >- " if (foo == null) {}\n" + >- " ^^\n" + >- "Dead code\n" + >- "----------\n" + >- "3. ERROR in X.java (at line 9)\n" + >+ "2. ERROR in X.java (at line 9)\n" + > " if (foo2 == null) {}\n" + > " ^^^^\n" + > "Redundant null check: The variable foo2 can only be null at this location\n" + > "----------\n" + >- "4. ERROR in X.java (at line 12)\n" + >+ "3. ERROR in X.java (at line 12)\n" + > " if (bar == null) {}\n" + > " ^^^\n" + > "Redundant null check: The variable bar can only be null at this location\n" + > "----------\n" + >- "5. ERROR in X.java (at line 15)\n" + >+ "4. ERROR in X.java (at line 15)\n" + > " if (bar2 == null) {}\n" + > " ^^^^\n" + > "Null comparison always yields false: The variable bar2 cannot be null at this location\n" + >- "----------\n" + >- "6. WARNING in X.java (at line 15)\n" + >- " if (bar2 == null) {}\n" + >- " ^^\n" + >- "Dead code\n" + > "----------\n", > JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); > } >@@ -8579,30 +8534,20 @@ > " ^^^\n" + > "Null comparison always yields false: The variable foo cannot be null at this location\n" + > "----------\n" + >- "2. WARNING in X.java (at line 12)\n" + >- " if (foo == null) {}\n" + >- " ^^\n" + >- "Dead code\n" + >- "----------\n" + >- "3. ERROR in X.java (at line 14)\n" + >+ "2. ERROR in X.java (at line 14)\n" + > " if (foo2 == null) {}\n" + > " ^^^^\n" + > "Redundant null check: The variable foo2 can only be null at this location\n" + > "----------\n" + >- "4. ERROR in X.java (at line 16)\n" + >+ "3. ERROR in X.java (at line 16)\n" + > " if (bar == null) {}\n" + > " ^^^\n" + > "Redundant null check: The variable bar can only be null at this location\n" + > "----------\n" + >- "5. ERROR in X.java (at line 18)\n" + >+ "4. ERROR in X.java (at line 18)\n" + > " if (bar2 == null) {}\n" + > " ^^^^\n" + > "Null comparison always yields false: The variable bar2 cannot be null at this location\n" + >- "----------\n" + >- "6. WARNING in X.java (at line 18)\n" + >- " if (bar2 == null) {}\n" + >- " ^^\n" + >- "Dead code\n" + > "----------\n", > JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); > }
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 303448
: 160043