diff options
Diffstat (limited to 'org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java')
-rw-r--r-- | org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java index 9a87b4963..af54844e0 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java @@ -17,6 +17,7 @@ * bug 349326 - [1.7] new warning for missing try-with-resources * bug 186342 - [compiler][null] Using annotations for null checking * bug 358903 - Filter practically unimportant resource leak warnings + * bug 370639 - [compiler][resource] restore the default for resource leak warnings *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -74,46 +75,44 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl // record setting a variable: various scenarii are possible, setting an array reference, // a field reference, a blank final field reference, a field of an enclosing instance or // just a local variable. - VariableBinding var = this.lhs.variableBinding(currentScope); + LocalVariableBinding local = this.lhs.localVariableBinding(); if ((this.expression.implicitConversion & TypeIds.UNBOXING) != 0) { this.expression.checkNPE(currentScope, flowContext, flowInfo); } FlowInfo preInitInfo = null; - LocalVariableBinding localToAnalyseAsResource = null; - if (var instanceof LocalVariableBinding - && flowInfo.reachMode() == FlowInfo.REACHABLE + boolean shouldAnalyseResource = local != null + && flowInfo.reachMode() == FlowInfo.REACHABLE + && currentScope.compilerOptions().analyseResourceLeaks && (FakedTrackingVariable.isAnyCloseable(this.expression.resolvedType) - || this.expression.resolvedType == TypeBinding.NULL)) { - localToAnalyseAsResource = (LocalVariableBinding) var; - + || this.expression.resolvedType == TypeBinding.NULL); + if (shouldAnalyseResource) { preInitInfo = flowInfo.unconditionalCopy(); // analysis of resource leaks needs additional context while analyzing the RHS: - FakedTrackingVariable.preConnectTrackerAcrossAssignment(this, localToAnalyseAsResource, this.expression); + FakedTrackingVariable.preConnectTrackerAcrossAssignment(this, local, this.expression); } flowInfo = ((Reference) this.lhs) .analyseAssignment(currentScope, flowContext, flowInfo, this, false) .unconditionalInits(); - if (localToAnalyseAsResource != null) { - FakedTrackingVariable.handleResourceAssignment(currentScope, preInitInfo, flowInfo, this, this.expression, localToAnalyseAsResource); - } else { + if (shouldAnalyseResource) + FakedTrackingVariable.handleResourceAssignment(currentScope, preInitInfo, flowInfo, this, this.expression, local); + else FakedTrackingVariable.cleanUpAfterAssignment(currentScope, this.lhs.bits, this.expression); - } int nullStatus = this.expression.nullStatus(flowInfo); - if (var != null && (var.type.tagBits & TagBits.IsBaseType) == 0) { + if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0) { if (nullStatus == FlowInfo.NULL) { - flowContext.recordUsingNullReference(currentScope, var, this.lhs, + flowContext.recordUsingNullReference(currentScope, local, this.lhs, FlowContext.CAN_ONLY_NULL | FlowContext.IN_ASSIGNMENT, flowInfo); } } - nullStatus = checkAssignmentAgainstNullAnnotation(currentScope, flowContext, var, nullStatus, this.expression); - if (var != null && (var.type.tagBits & TagBits.IsBaseType) == 0) { - flowInfo.markNullStatus(var, nullStatus); + nullStatus = checkAssignmentAgainstNullAnnotation(currentScope, flowContext, local, nullStatus, this.expression); + if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0) { + flowInfo.markNullStatus(local, nullStatus); if (flowContext.initsOnFinally != null) - flowContext.initsOnFinally.markNullStatus(var, nullStatus); + flowContext.initsOnFinally.markNullStatus(local, nullStatus); } return flowInfo; } @@ -291,7 +290,4 @@ public void traverse(ASTVisitor visitor, BlockScope scope) { public LocalVariableBinding localVariableBinding() { return this.lhs.localVariableBinding(); } -public VariableBinding variableBinding(Scope scope) { - return this.lhs.variableBinding(scope); -} } |