import java.io.*;

public class OpenStream {
	public OutputStream os;

	public static void main(String[] argv) throws Exception {
		FileInputStream in = null;

		try {
			in = new FileInputStream(argv[0]);
		} finally {
			// Not guaranteed to be closed here!
			if (Boolean.getBoolean("inscrutable"))
				in.close();
		}

		FileInputStream in2 = null;
		try {
			in2 = new FileInputStream(argv[1]);
		} finally {
			// This one will be closed
			if (in2 != null)
				in2.close();
		}

		// oops! exiting the method without closing the stream
	}

	public void byteArrayStreamDoNotReport() {
		ByteArrayOutputStream b = new ByteArrayOutputStream();
		PrintStream out = new PrintStream(b);

		out.println("Hello, world!");
	}

	public void systemInDoNotReport() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		System.out.println(reader.readLine());
	}

	public void socketDoNotReport(java.net.Socket socket) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		System.out.println(reader.readLine());
	}

	public void paramStreamDoNotReport(java.io.OutputStream os) throws IOException {
		PrintStream ps = new PrintStream(os);
		ps.println("Hello");
	}

	public void loadFromFieldDoNotReport() throws IOException {
		OutputStream outputStream = os;
		PrintStream ps = new PrintStream(outputStream);
		ps.println("Hello");
	}

	public void wrappedStreamClosedDoNotReport() throws IOException {
		FileOutputStream f = null;
		try {
			f = new FileOutputStream("Hello.txt");
			PrintStream ps = new PrintStream(f);
			ps.println("Hello");
		} finally {
			if (f != null)
				f.close();
		}
	}
}

// vim:ts=4

@@ -10,16 +10,54 @@
 va.io.*;
+%0Aimport java.nio.channels.FileChannel;
 %0A%0Apublic
@@ -1737,16 +1737,717 @@
 %0A%09%09%7D%0A%09%7D%0A
+%0A%09public static FileChannel createChannelDoNotReport(String fname) throws IOException %7B%0A%09%09FileInputStream fis = new FileInputStream(fname);%0A%09%09FileChannel ch = fis.getChannel();%0A%09%09return ch; // stream escapes via FileChannel%0A%09%7D%0A%09%0A%09public static long sizeViaChannel(String fname) throws IOException %7B%0A%09%09FileInputStream fis = new FileInputStream(fname);%0A%09%09FileChannel ch = fis.getChannel();%0A%09%09return ch.size(); // nothing escapes, probably should report%0A%09%7D%0A%0A%09public static long sizeViaChannelCloseDoNotReport(String fname) throws IOException %7B%0A%09%09FileInputStream fis = new FileInputStream(fname);%0A%09%09FileChannel ch = fis.getChannel();%0A%09%09long sz = ch.size();%0A%09%09//fis.close();%0A%09%09ch.close();%0A%09%09return sz;%0A%09%7D%0A%0A
 %7D%0A%0A// vi

test cases inspired by bug#1560564 ] False OS when creating FileChannel (Radim Kubacki)