|
|
@ -6,9 +6,7 @@
|
|
|
|
package endtoend.java.infer;
|
|
|
|
package endtoend.java.infer;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
|
import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
|
import static utils.matchers.ResultContainsErrorInMethod.contains;
|
|
|
|
import static utils.matchers.ResultContainsExactly.containsExactly;
|
|
|
|
import static utils.matchers.ResultContainsNoErrorInMethod.doesNotContain;
|
|
|
|
|
|
|
|
import static utils.matchers.ResultContainsOnlyTheseErrors.containsOnly;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
@ -20,7 +18,7 @@ import utils.InferResults;
|
|
|
|
|
|
|
|
|
|
|
|
public class FilterOutputStreamLeaksTest {
|
|
|
|
public class FilterOutputStreamLeaksTest {
|
|
|
|
|
|
|
|
|
|
|
|
public static final String FilterOutputStreamLeaks =
|
|
|
|
public static final String SOURCE_FILE =
|
|
|
|
"infer/tests/codetoanalyze/java/infer/FilterOutputStreamLeaks.java";
|
|
|
|
"infer/tests/codetoanalyze/java/infer/FilterOutputStreamLeaks.java";
|
|
|
|
|
|
|
|
|
|
|
|
public static final String RESOURCE_LEAK = "RESOURCE_LEAK";
|
|
|
|
public static final String RESOURCE_LEAK = "RESOURCE_LEAK";
|
|
|
@ -31,319 +29,34 @@ public class FilterOutputStreamLeaksTest {
|
|
|
|
public static void loadResults() throws InterruptedException, IOException {
|
|
|
|
public static void loadResults() throws InterruptedException, IOException {
|
|
|
|
inferResults = InferResults.loadInferResults(
|
|
|
|
inferResults = InferResults.loadInferResults(
|
|
|
|
FilterOutputStreamLeaksTest.class,
|
|
|
|
FilterOutputStreamLeaksTest.class,
|
|
|
|
FilterOutputStreamLeaks);
|
|
|
|
SOURCE_FILE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//FilterOutputStream tests
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void whenInferRunsOnFilterOutputStreamNotClosedAfterThenRLIsFound()
|
|
|
|
public void test()
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
assertThat(
|
|
|
|
String[] methods = {
|
|
|
|
"Results should contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
contains(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"filterOutputStreamNotClosedAfterWrite"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnFilterOutputStreamClosedAfterThenRLIsNotFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should not contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
doesNotContain(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"filterOutputStreamClosedAfterWrite"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//DataOutputStream tests
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnDataOutputStreamNotClosedAfterThenRLIsFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
contains(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"dataOutputStreamNotClosedAfterWrite"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnDataOutputStreamClosedAfterThenRLIsNotFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should not contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
doesNotContain(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"dataOutputStreamClosedAfterWrite"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//BufferedOutputStream tests
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnBufferedOutputStreamNotClosedAfterThenRLIsFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
contains(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"bufferedOutputStreamNotClosedAfterWrite"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnBufferedOutputStreamClosedAftThenRLIsNotFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should not contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
doesNotContain(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"bufferedOutputStreamClosedAfterWrite"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//CheckedOutputStream tests
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnCheckedOutputStreamNotClosedAfterThenRLIsFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
contains(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"checkedOutputStreamNotClosedAfterWrite"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnCheckedOutputStreamClosedAfterThenRLIsNotFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should not contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
doesNotContain(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"checkedOutputStreamClosedAfterWrite"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//CipherOutputStream tests
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnCipherOutputStreamNotClosedAfterThenRLIsFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
contains(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"cipherOutputStreamNotClosedAfterWrite"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnCipherOutputStreamClosedAfterThenRLIsNotFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should not contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
doesNotContain(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"cipherOutputStreamClosedAfterWrite"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//DeflaterOutputStream tests
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnDeflaterOutputStreamNotClosedAfterThenRLIsFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
contains(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"deflaterOutputStreamNotClosedAfterWrite"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnDeflaterOutputStreamClosedAfterThenRLIsNotFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should not contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
doesNotContain(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"deflaterOutputStreamClosedAfterWrite"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//GZipOutputStream tests
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnGzipOutputStreamNotClosedAfterThenRLIsFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
contains(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"gzipOutputStreamNotClosedAfterFlush"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnGzipOutputStreamClosedAfterThenRLIsNotFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should not contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
doesNotContain(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"gzipOutputStreamClosedAfterWrite"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//DigestOutputStream tests
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnDigestOutputStreamNotClosedAfterThenRLIsFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
contains(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"digestOutputStreamNotClosedAfterWrite"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnDigestOutputStreamClosedAfterThenRLIsNotFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should not contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
doesNotContain(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"digestOutputStreamClosedAfterWrite"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//InflaterOutputStream tests
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnInflaterOutputStreamNotClosedAfterThenRLIsFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
contains(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"inflaterOutputStreamNotClosedAfterWrite"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnInflaterOutputStreamClosedAfterThenRLIsNotFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should not contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
doesNotContain(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"inflaterOutputStreamClosedAfterWrite"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//PrintStream tests
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnPrintStreamNotClosedAfterWriteThenRLIsFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
contains(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"printStreamNotClosedAfterWrite"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnPrintStreamClosedAfterWriteThenRLIsNotFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
assertThat(
|
|
|
|
|
|
|
|
"Results should not contain a resource leak error",
|
|
|
|
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
doesNotContain(
|
|
|
|
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
|
|
|
|
"printStreamClosedAfterWrite"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void whenInferRunsOnResourceLeaksThenOnlyTheExpectedErrorsAreFound()
|
|
|
|
|
|
|
|
throws InterruptedException, IOException, InferException {
|
|
|
|
|
|
|
|
String[] expectedMethods = {
|
|
|
|
|
|
|
|
"filterOutputStreamNotClosedAfterWrite",
|
|
|
|
"filterOutputStreamNotClosedAfterWrite",
|
|
|
|
"filterOutputStreamClosedAfterWrite",
|
|
|
|
|
|
|
|
"dataOutputStreamNotClosedAfterWrite",
|
|
|
|
"dataOutputStreamNotClosedAfterWrite",
|
|
|
|
"dataOutputStreamClosedAfterWrite",
|
|
|
|
|
|
|
|
"bufferedOutputStreamNotClosedAfterWrite",
|
|
|
|
"bufferedOutputStreamNotClosedAfterWrite",
|
|
|
|
"bufferedOutputStreamClosedAfterWrite",
|
|
|
|
|
|
|
|
"checkedOutputStreamNotClosedAfterWrite",
|
|
|
|
"checkedOutputStreamNotClosedAfterWrite",
|
|
|
|
"checkedOutputStreamClosedAfterWrite",
|
|
|
|
|
|
|
|
"cipherOutputStreamNotClosedAfterWrite",
|
|
|
|
"cipherOutputStreamNotClosedAfterWrite",
|
|
|
|
"cipherOutputStreamClosedAfterWrite",
|
|
|
|
|
|
|
|
"deflaterOutputStreamNotClosedAfterWrite",
|
|
|
|
"deflaterOutputStreamNotClosedAfterWrite",
|
|
|
|
"deflaterOutputStreamClosedAfterWrite",
|
|
|
|
|
|
|
|
"digestOutputStreamNotClosedAfterWrite",
|
|
|
|
"digestOutputStreamNotClosedAfterWrite",
|
|
|
|
"digestOutputStreamClosedAfterWrite",
|
|
|
|
|
|
|
|
"inflaterOutputStreamNotClosedAfterWrite",
|
|
|
|
"inflaterOutputStreamNotClosedAfterWrite",
|
|
|
|
"inflaterOutputStreamClosedAfterWrite",
|
|
|
|
|
|
|
|
"gzipOutputStreamNotClosedAfterFlush",
|
|
|
|
"gzipOutputStreamNotClosedAfterFlush",
|
|
|
|
"gzipOutputStreamClosedAfterWrite",
|
|
|
|
"gzipOutputStreamNotClosedAfterFlush",
|
|
|
|
"printStreamNotClosedAfterWrite",
|
|
|
|
"printStreamNotClosedAfterWrite",
|
|
|
|
"printStreamClosedAfterWrite",
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
assertThat(
|
|
|
|
assertThat(
|
|
|
|
"No unexpected errors should be found", inferResults,
|
|
|
|
"Results should contain a resource leak error",
|
|
|
|
containsOnly(
|
|
|
|
inferResults,
|
|
|
|
|
|
|
|
containsExactly(
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
RESOURCE_LEAK,
|
|
|
|
FilterOutputStreamLeaks,
|
|
|
|
SOURCE_FILE,
|
|
|
|
expectedMethods));
|
|
|
|
methods
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|