diff options
Diffstat (limited to 'org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java')
-rw-r--r-- | org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java index 6608e849e..f84c47219 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java @@ -15,6 +15,8 @@ * 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 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK + * bug 370639 - [compiler][resource] restore the default for resource leak warnings *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -85,7 +87,9 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl // process arguments if (this.arguments != null) { - boolean hasResourceWrapperType = this.resolvedType instanceof ReferenceBinding + boolean analyseResources = currentScope.compilerOptions().analyseResourceLeaks; + boolean hasResourceWrapperType = analyseResources + && this.resolvedType instanceof ReferenceBinding && ((ReferenceBinding)this.resolvedType).hasTypeBit(TypeIds.BitWrapperCloseable); for (int i = 0, count = this.arguments.length; i < count; i++) { flowInfo = @@ -93,7 +97,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl .analyseCode(currentScope, flowContext, flowInfo) .unconditionalInits(); // if argument is an AutoCloseable insert info that it *may* be closed (by the target method, i.e.) - if (!hasResourceWrapperType) { // allocation of wrapped closeables is analyzed specially + if (analyseResources && !hasResourceWrapperType) { // allocation of wrapped closeables is analyzed specially flowInfo = FakedTrackingVariable.markPassedToOutside(currentScope, this.arguments[i], flowInfo, false); } if ((this.arguments[i].implicitConversion & TypeIds.UNBOXING) != 0) { @@ -103,9 +107,6 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl analyseArguments(currentScope, flowContext, flowInfo, this.binding, this.arguments); } - if (FakedTrackingVariable.isAnyCloseable(this.resolvedType)) - FakedTrackingVariable.analyseCloseableAllocation(currentScope, flowInfo, this); - // record some dependency information for exception types ReferenceBinding[] thrownExceptions; if (((thrownExceptions = this.binding.thrownExceptions).length) != 0) { @@ -120,6 +121,11 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl flowInfo.unconditionalCopy(), currentScope); } + + // after having analysed exceptions above start tracking newly allocated resource: + if (FakedTrackingVariable.isAnyCloseable(this.resolvedType) && currentScope.compilerOptions().analyseResourceLeaks) + FakedTrackingVariable.analyseCloseableAllocation(currentScope, flowInfo, this); + if (this.binding.declaringClass.isMemberType() && !this.binding.declaringClass.isStatic()) { // allocating a non-static member type without an enclosing instance of parent type // https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 |