View | Details | Raw Unified | Return to bug 368709
Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java (-2 / +85 lines)
Lines 26-32 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; Link Here
26
public class ResourceLeakTests extends AbstractRegressionTest {
26
public class ResourceLeakTests extends AbstractRegressionTest {
27
27
28
static {
28
static {
29
//	TESTS_NAMES = new String[] { "test061l"};
29
	TESTS_NAMES = new String[] { "testBug368709b"};
30
//	TESTS_NUMBERS = new int[] { 50 };
30
//	TESTS_NUMBERS = new int[] { 50 };
31
//	TESTS_RANGE = new int[] { 11, -1 };
31
//	TESTS_RANGE = new int[] { 11, -1 };
32
}
32
}
Lines 3085-3089 public void test063e() { Link Here
3085
		options,
3085
		options,
3086
		null);
3086
		null);
3087
}
3087
}
3088
3088
// Bug 368709 - Endless loop in FakedTrackingVariable.markPassedToOutside
3089
// original test case from jgit
3090
public void testBug368709a() {
3091
	if (this.complianceLevel < ClassFileConstants.JDK1_5) return;
3092
	Map options = getCompilerOptions();
3093
	options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR);
3094
	options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR);
3095
	this.runConformTest(
3096
		new String[] {
3097
			"X.java",
3098
			"import java.io.*;\n" +
3099
			"import java.util.zip.*;\n" +
3100
			"public class X {\n" +
3101
			"  Object db, pack;\n" + // mock
3102
			"  int objectOffset, headerLength, type, size;\n" +
3103
			"  public ObjectStream openStream() throws MissingObjectException, IOException {\n" + 
3104
			"    WindowCursor wc = new WindowCursor(db);\n" + 
3105
			"    InputStream in;\n" + 
3106
			"    try\n" + 
3107
			"      {\n" + 
3108
			"        in = new PackInputStream(pack, (objectOffset + headerLength), wc);\n" + 
3109
			"      }\n" + 
3110
			"    catch (IOException packGone)\n" + 
3111
			"      {\n" + 
3112
			"        return wc.open(getObjectId(), type).openStream();\n" + 
3113
			"      }\n" + 
3114
			"    in = new BufferedInputStream(new InflaterInputStream(in, wc.inflater(), 8192), 8192);\n" + 
3115
			"    return new ObjectStream.Filter(type, size, in);\n" + 
3116
			"  }\n" +
3117
			"  String getObjectId() { return \"\"; }\n" + // mock
3118
			"}\n" +
3119
			// mock:
3120
			"class WindowCursor {\n" +
3121
			"    WindowCursor(Object db) {}\n" +
3122
			"    ObjectStream open(String id, int type) { return null; }\n" +
3123
			"    Inflater inflater() { return null; }\n" +
3124
			"}\n" +
3125
			"class MissingObjectException extends Exception { MissingObjectException() { super();} }\n" +
3126
			"class PackInputStream extends InputStream {\n" +
3127
			"    PackInputStream(Object pack, int offset, WindowCursor wc) {}\n" +
3128
			"}\n" +
3129
			"class ObjectStream extends InputStream {\n" +
3130
			"    static class Filter extends ObjectStream {\n" +
3131
			"        Filter(int type, int size, InputStream in) { }\n" +
3132
			"    }\n" +
3133
			"    ObjectStream openStream() { return this; }\n" +
3134
			"}\n"
3135
		},
3136
		"",
3137
		null,
3138
		true,
3139
		null,
3140
		options,
3141
		null);
3142
}
3143
//Bug 368709 - Endless loop in FakedTrackingVariable.markPassedToOutside
3144
//original test case from jgit
3145
public void testBug368709b() {
3146
	if (this.complianceLevel < ClassFileConstants.JDK1_5) return;
3147
	Map options = getCompilerOptions();
3148
	options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR);
3149
	options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR);
3150
	this.runConformTest(
3151
		new String[] {
3152
			"X.java",
3153
			"import java.io.*;\n" +
3154
			"import java.util.zip.*;\n" +
3155
			"public class X {\n" +
3156
			"  void doit() throws IOException {\n" + 
3157
			"    InputStream in = new FileInputStream(\"somefile\");\n" + 
3158
			"    in = new BufferedInputStream(new InflaterInputStream(in, inflater(), 8192), 8192);\n" + 
3159
			"    process(in);\n" +
3160
			"  }\n" +
3161
			"  Inflater inflater() { return null; }\n" +
3162
			"  void process(InputStream is) { }\n" +
3163
			"}\n"
3164
		},
3165
		"",
3166
		null,
3167
		true,
3168
		null,
3169
		options,
3170
		null);
3171
}
3089
}
3172
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/FakedTrackingVariable.java (-2 / +6 lines)
Lines 209-216 public class FakedTrackingVariable extends LocalDeclaration { Link Here
209
				// find the wrapped resource represented by its tracking var:
209
				// find the wrapped resource represented by its tracking var:
210
				FakedTrackingVariable innerTracker = findCloseTracker(scope, flowInfo, allocation.arguments[0]);
210
				FakedTrackingVariable innerTracker = findCloseTracker(scope, flowInfo, allocation.arguments[0]);
211
				if (innerTracker != null) {
211
				if (innerTracker != null) {
212
					if (innerTracker == allocation.closeTracker)
212
					FakedTrackingVariable currentInner = innerTracker;
213
						return; // self wrap (res = new Res(res)) -> neither change (here) nor remove (below)
213
					while (currentInner != null) {
214
						if (currentInner == allocation.closeTracker)
215
							return; // self wrap (res = new Res(res)) -> neither change (here) nor remove (below)
216
						currentInner = currentInner.innerTracker;
217
					}
214
					int newStatus = FlowInfo.NULL;
218
					int newStatus = FlowInfo.NULL;
215
					if (allocation.closeTracker == null) {
219
					if (allocation.closeTracker == null) {
216
						allocation.closeTracker = new FakedTrackingVariable(scope, allocation); // no local available, closeable is unassigned
220
						allocation.closeTracker = new FakedTrackingVariable(scope, allocation); // no local available, closeable is unassigned

Return to bug 368709