Skip to content

Commit

Permalink
Eclipse 4.10 (RC2) JDT Patch for Groovy-Eclipse: JDT commit 178dc27
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Dec 7, 2018
1 parent b0b7179 commit edfaa10
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</license>

<requires>
<import feature="org.eclipse.jdt" version="3.16.0.v20181129-0401" patch="true"/>
<import feature="org.eclipse.jdt" version="3.16.0.v20181206-1038" patch="true"/>
</requires>

<plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5437,4 +5437,63 @@ public void testBug473317() {
"----------\n",
compilerOptions);
}
public void testBug541705() {
if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // uses diamond
Runner runner = new Runner();
runner.customOptions = getCompilerOptions();
runner.customOptions.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR);
runner.testFiles = new String[] {
"Test.java",
"import java.util.*;\n" +
"import java.util.zip.*;\n" +
"import java.io.*;\n" +
"public class Test {\n" +
" private static HashMap<String, ZipFile> fgZipFileCache = new HashMap<>(5);\n" +
" public static void closeArchives() {\n" +
" synchronized (fgZipFileCache) {\n" +
" for (ZipFile file : fgZipFileCache.values()) {\n" +
" synchronized (file) {\n" +
" try {\n" +
" file.close();\n" +
" } catch (IOException e) {\n" +
" System.out.println(e);\n" +
" }\n" +
" }\n" +
" }\n" +
" fgZipFileCache.clear();\n" +
" }\n" +
" }\n" +
"}\n"
};
runner.runConformTest();
}
public void testBug541705b() {
if (this.complianceLevel < ClassFileConstants.JDK9) return; // variable used in t-w-r
Runner runner = new Runner();
runner.customOptions = getCompilerOptions();
runner.customOptions.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR);
runner.testFiles = new String[] {
"Test.java",
"import java.util.*;\n" +
"import java.util.zip.*;\n" +
"import java.io.*;\n" +
"public class Test {\n" +
" private static HashMap<String, ZipFile> fgZipFileCache = new HashMap<>(5);\n" +
" public static void closeArchives() {\n" +
" synchronized (fgZipFileCache) {\n" +
" for (ZipFile file : fgZipFileCache.values()) {\n" +
" synchronized (file) {\n" +
" try (file) {\n" +
" } catch (IOException e) {\n" +
" System.out.println(e);\n" +
" }\n" +
" }\n" +
" }\n" +
" fgZipFileCache.clear();\n" +
" }\n" +
" }\n" +
"}\n"
};
runner.runConformTest();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public class FakedTrackingVariable extends LocalDeclaration {
private static final int REPORTED_POTENTIAL_LEAK = 32;
// a location independent definitive problem has been reported against this resource:
private static final int REPORTED_DEFINITIVE_LEAK = 64;

// a local declarations that acts as the element variable of a foreach loop (should never suggest to use t-w-r):
private static final int FOREACH_ELEMENT_VAR = 128;

public static boolean TEST_372319 = false; // see https://bugs.eclipse.org/372319

/**
Expand Down Expand Up @@ -449,9 +451,9 @@ public static void handleResourceAssignment(BlockScope scope, FlowInfo upstreamI
if (rhsTrackVar.originalBinding != null)
local.closeTracker = rhsTrackVar; // a.: let fresh LHS share it
if (rhsTrackVar.currentAssignment == location) {
// pre-set tracker from lhs - passed from outside?
// pre-set tracker from lhs - passed from outside (or foreach)?
// now it's a fresh resource
rhsTrackVar.globalClosingState &= ~(SHARED_WITH_OUTSIDE|OWNED_BY_OUTSIDE);
rhsTrackVar.globalClosingState &= ~(SHARED_WITH_OUTSIDE|OWNED_BY_OUTSIDE|FOREACH_ELEMENT_VAR);
}
} else {
if (rhs instanceof AllocationExpression || rhs instanceof ConditionalExpression) {
Expand Down Expand Up @@ -484,7 +486,7 @@ public static void handleResourceAssignment(BlockScope scope, FlowInfo upstreamI
}
}
// re-assigning from a fresh value, mark as not-closed again:
if ((previousTracker.globalClosingState & (SHARED_WITH_OUTSIDE|OWNED_BY_OUTSIDE)) == 0
if ((previousTracker.globalClosingState & (SHARED_WITH_OUTSIDE|OWNED_BY_OUTSIDE|FOREACH_ELEMENT_VAR)) == 0
&& flowInfo.hasNullInfoFor(previousTracker.binding)) // avoid spilling info into a branch that doesn't see the corresponding resource
flowInfo.markAsDefinitelyNull(previousTracker.binding);
local.closeTracker = analyseCloseableExpression(flowInfo, flowContext, local, location, rhs, previousTracker);
Expand All @@ -494,7 +496,7 @@ public static void handleResourceAssignment(BlockScope scope, FlowInfo upstreamI
if (rhsTrackVar != null) {
local.closeTracker = rhsTrackVar;
// a fresh resource, mark as not-closed:
if ((rhsTrackVar.globalClosingState & (SHARED_WITH_OUTSIDE|OWNED_BY_OUTSIDE)) == 0)
if ((rhsTrackVar.globalClosingState & (SHARED_WITH_OUTSIDE|OWNED_BY_OUTSIDE|FOREACH_ELEMENT_VAR)) == 0)
flowInfo.markAsDefinitelyNull(rhsTrackVar.binding);
// TODO(stephan): this might be useful, but I could not find a test case for it:
// if (flowContext.initsOnFinally != null)
Expand Down Expand Up @@ -753,6 +755,12 @@ public static FlowInfo markPassedToOutside(BlockScope scope, Expression expressi
return flowInfo;
}

public static void markForeachElementVar(LocalDeclaration local) {
if (local.binding != null && local.binding.closeTracker != null) {
local.binding.closeTracker.globalClosingState |= FOREACH_ELEMENT_VAR;
}
}

/**
* Iterator for a set of FakedTrackingVariable, which dispenses the elements
* according to the priorities defined by enum {@link Stage}.
Expand Down Expand Up @@ -987,7 +995,7 @@ public int reportError(ProblemReporter problemReporter, ASTNode location, int nu
}

public void reportExplicitClosing(ProblemReporter problemReporter) {
if ((this.globalClosingState & (OWNED_BY_OUTSIDE|REPORTED_EXPLICIT_CLOSE)) == 0) { // can't use t-w-r for OWNED_BY_OUTSIDE
if ((this.globalClosingState & (OWNED_BY_OUTSIDE|REPORTED_EXPLICIT_CLOSE|FOREACH_ELEMENT_VAR)) == 0) { // can't use t-w-r for OWNED_BY_OUTSIDE
this.globalClosingState |= REPORTED_EXPLICIT_CLOSE;
problemReporter.explicitlyClosedAutoCloseable(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
int initialComplaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED;

// process the element variable and collection
flowInfo = this.elementVariable.analyseCode(this.scope, flowContext, flowInfo);
flowInfo = this.elementVariable.analyseCode(this.scope, flowContext, flowInfo);
FlowInfo condInfo = this.collection.analyseCode(this.scope, flowContext, flowInfo.copy());
this.collection.checkNPE(currentScope, flowContext, condInfo.copy(), 1);
LocalVariableBinding elementVarBinding = this.elementVariable.binding;
Expand Down Expand Up @@ -132,6 +132,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
if (this.action.complainIfUnreachable(actionInfo, this.scope, initialComplaintLevel, true) < Statement.COMPLAINED_UNREACHABLE) {
actionInfo = this.action.analyseCode(this.scope, loopingContext, actionInfo).unconditionalCopy();
if (this.action instanceof Block) {
FakedTrackingVariable.markForeachElementVar(this.elementVariable);
// action.analyseCode() missed the following check due to identical scopes of ForeachStatement and Block:
this.scope.checkUnclosedCloseables(actionInfo, loopingContext, null, null);
}
Expand Down
1 change: 1 addition & 0 deletions jdt-patch/e410/org.eclipse.jdt.core/readme.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2018-10-16: e4fef6c (2018-12 M1)
2018-11-23: e806c1b (2018-12 M3)
2018-11-30: 2ea4c6b (2018-12 RC1)
2018-11-30: 178dc27 (2018-12 RC2)

0 comments on commit edfaa10

Please sign in to comment.