ClosedWriter.java revision 2362
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay/*
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay *
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * This code is free software; you can redistribute it and/or modify it
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * under the terms of the GNU General Public License version 2 only, as
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * published by the Free Software Foundation.
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay *
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * This code is distributed in the hope that it will be useful, but WITHOUT
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * version 2 for more details (a copy is included in the LICENSE file that
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * accompanied this code).
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay *
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * You should have received a copy of the GNU General Public License version
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * 2 along with this work; if not, write to the Free Software Foundation,
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay *
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * or visit www.oracle.com if you need additional information or have any
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * questions.
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay */
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay/*
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * @test
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * @bug 4130880
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * @summary reading inputstream from child process throws
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay * io exception: Write end dead
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay *
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay */
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemayimport java.io.*;
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemaypublic class ClosedWriter implements Runnable {
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay static PipedInputStream is;
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay static PipedOutputStream os;
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay public void run() {
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay try {
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay os.write(0);
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay os.write(0);
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay os.write(0);
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay os.write(0);
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay os.write(0);
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay os.close();
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay } catch (Exception e) {
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay e.printStackTrace();
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay }
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay }
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay public static void main(String[] args) throws Exception {
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay is = new PipedInputStream();
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay os = new PipedOutputStream();
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay is.connect(os);
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay Thread t = new Thread(new ClosedWriter());
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay t.start();
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay // this should just exit cleanly but the bug causes an exception
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay // to be thrown on the last read.
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay while (is.read() != -1) {
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay }
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay }
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay}
f58c87ece2202b8f85310d8885c7e39a7f435c09Jason Lemay