You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
4.6 KiB

/*
* Copyright (c) 2013 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package codetoanalyze.java.infer;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PipedReader;
import java.io.PipedWriter;
import java.io.PushbackReader;
import java.io.Reader;
public class ReaderLeaks {
//Reader tests
public void readerNotClosedAfterRead() {
Reader r;
try {
r = new FileReader("testing.txt");
r.read();
r.close();
} catch (IOException e) {
}
}
public void readerClosed() throws IOException {
Reader r = null;
try {
r = new FileReader("testing.txt");
boolean ready = r.ready();
r.close();
} catch (IOException e) {
} finally {
if (r != null) r.close();
}
}
//BufferedReader tests
public void bufferedReaderNotClosedAfterRead() {
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader("testing.txt"));
reader.read();
reader.close();
} catch (IOException e) {
}
}
public void bufferedReaderClosed() throws IOException {
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("testing.txt"));
reader.read();
} catch (IOException e) {
} finally {
if (reader != null) reader.close();
}
}
//InputStreamReader tests
public void inputStreamReaderNotClosedAfterRead() {
InputStreamReader reader;
try {
reader = new InputStreamReader(new FileInputStream("testing.txt"));
reader.read();
reader.close();
} catch (IOException e) {
}
}
public void inputStreamReaderClosed() throws IOException {
InputStreamReader reader = null;
try {
reader = new InputStreamReader(new FileInputStream("testing.txt"));
reader.read();
} catch (IOException e) {
} finally {
if (reader != null) reader.close();
}
}
//FileReader tests
public void fileReaderNotClosedAfterRead() {
FileReader reader;
try {
reader = new FileReader("testing.txt");
reader.read();
reader.close();
} catch (IOException e) {
}
}
public void fileReaderClosed() throws IOException {
FileReader reader = null;
try {
reader = new FileReader("testing.txt");
reader.read();
} catch (IOException e) {
} finally {
if (reader != null) reader.close();
}
}
//PushbackReader tests
public void pushbackReaderNotClosedAfterRead() {
PushbackReader reader;
try {
reader = new PushbackReader(new InputStreamReader(new FileInputStream("testing.txt")));
reader.read();
reader.close();
} catch (IOException e) {
}
}
public void pushbackReaderClosed() throws IOException {
PushbackReader reader = null;
try {
reader = new PushbackReader(new InputStreamReader(new FileInputStream("testing.txt")));
reader.read();
} catch (IOException e) {
} finally {
if (reader != null) reader.close();
}
}
//PipedReader tests
public void pipedReaderNotClosedAfterConstructedWithWriter() {
PipedReader reader;
PipedWriter writer;
try {
writer = new PipedWriter();
reader = new PipedReader(writer);
reader.read();
reader.close();
} catch (IOException e) {
}
}
public void pipedReaderNotClosedAfterConnect(PipedWriter writer) {
PipedReader reader;
try {
reader = new PipedReader();
reader.connect(writer);
reader.read();
reader.close();
} catch (IOException e) {
}
}
public void pipedReaderNotConnected() {
PipedReader reader;
try {
reader = new PipedReader();
reader.close();
} catch (IOException e) {
}
}
public void pipedReaderClosed(PipedWriter writer) throws IOException {
PipedReader reader = null;
try {
reader = new PipedReader();
reader.connect(writer);
reader.read();
} catch (IOException e) {
} finally {
if (reader != null)
reader.close();
}
}
public void pipedReaderFalsePositive() throws IOException {
PipedReader reader;
PipedWriter writer = null;
try {
reader = new PipedReader(writer);
reader.read();
} catch (IOException e) {
} finally {
if (writer != null)
writer.close();
}
}
}