Initial load
diff --git a/test/java/io/PrintWriter/CheckError.java b/test/java/io/PrintWriter/CheckError.java
new file mode 100644
index 0000000..c91aad4
--- /dev/null
+++ b/test/java/io/PrintWriter/CheckError.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4213822
+ * @summary Test that checkError() returns a correct value
+ *      when a PrintWriter is wrapped with another
+ *      PrintWriter.
+ */
+
+import java.io.*;
+
+public class CheckError {
+    public static void main(String[] args) throws Exception {
+
+        boolean passTest1 = false;
+        File file = new File(System.getProperty("test.dir", "."),
+                          "junkie.out");
+
+        FileWriter fw = new FileWriter(file);
+
+        PrintWriter ppw  = new PrintWriter(
+                           new PrintWriter(fw));
+
+        fw.close();
+        ppw.println("Hello World!");
+
+        file.deleteOnExit();
+
+        if (ppw.checkError()) {
+            System.out.println("Correct: An error occured in the" +
+                " underlying writer");
+            passTest1 = true;
+        }
+        ppw.close();
+
+        // Test when the underlying stream is a PrintStream
+        FileOutputStream fos = new FileOutputStream(file);
+        PrintWriter pps  = new PrintWriter(
+                            new PrintStream(fos));
+
+        fos.close();
+        pps.println("Hello World!");
+
+        if (pps.checkError()) {
+            System.out.println("Correct: An error occured in the" +
+                " underlying Stream");
+        } else {
+            if (!passTest1) {
+                throw new Exception("CheckError() returned an incorrect value" +
+                    " when error occured in the underlying Stream" +
+                        " and when error occured in the underlying writer");
+            } else {
+                throw new Exception("CheckError() returned an incorrect value" +
+                    " when the error has occured in the underlying Stream");
+            }
+        }
+        if (!passTest1) {
+                throw new Exception("CheckError() returned an incorrect value" +
+                    " when the error has occured in the underlying Writer");
+        }
+        pps.close();
+    }
+}
diff --git a/test/java/io/PrintWriter/ClearErrorWriter.java b/test/java/io/PrintWriter/ClearErrorWriter.java
new file mode 100644
index 0000000..9ac02f7
--- /dev/null
+++ b/test/java/io/PrintWriter/ClearErrorWriter.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug  4491255
+ * @summary Test for a new protected method PrintWriter.clearError()
+ *          to reset its internal error state
+ */
+
+import java.io.*;
+
+public class ClearErrorWriter extends PrintWriter {
+
+
+    public ClearErrorWriter(Writer w, boolean autoFlush) {
+        super(w, autoFlush);
+    }
+
+    public static void main(String[] args) throws Exception {
+
+        File f = new File(System.getProperty("test.dir", "."),
+                          "print-writer.out");
+        f.deleteOnExit();
+        ClearErrorWriter out = new ClearErrorWriter(new BufferedWriter(
+                                new FileWriter(f)),
+                                true);
+        out.println("Hello World!");
+        out.close();
+        out.println("Writing after close");
+
+        if (out.checkError()) {
+            System.out.println("An error occured");
+            out.clearError();
+
+            if (!out.checkError()) {
+                System.out.println("Error status cleared");
+            } else {
+                throw new Exception("Error Status unchanged");
+            }
+         }
+         else {
+             System.out.println(" No error occured");
+         }
+    }
+}
diff --git a/test/java/io/PrintWriter/OpsAfterClose.java b/test/java/io/PrintWriter/OpsAfterClose.java
new file mode 100644
index 0000000..048132b
--- /dev/null
+++ b/test/java/io/PrintWriter/OpsAfterClose.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ *  @test
+ *  @bug 5085148
+ *  @summary Test if PrintWriter methods check if the stream
+ *           has been closed.
+ */
+
+import java.io.*;
+
+public enum OpsAfterClose {
+
+        WRITE_BUF { boolean check(PrintWriter w) {
+                    char buf[] = new char[2];
+                    w.write(buf);
+                    return w.checkError();
+            } },
+
+        WRITE_BUF_OFF { boolean check(PrintWriter w) {
+                    char buf[] = new char[2];
+                    int len = 1;
+                    w.write(buf, 0, len);
+                    return w.checkError();
+             } },
+        WRITE_INT { boolean check(PrintWriter w) {
+                    w.write(1);
+                    return w.checkError();
+             } },
+        WRITE_STR { boolean check(PrintWriter w) {
+                    String s = "abc";
+                    w.write(s);
+                    return w.checkError();
+             } },
+        WRITE_STR_OFF { boolean check(PrintWriter w) {
+                    String s = "abc";
+                    w.write(s, 0, s.length());
+                    return w.checkError();
+             } };
+
+    abstract boolean check(PrintWriter w);
+
+    public static void main(String args[]) throws Exception {
+
+        System.out.println("Testing PrintWriter");
+        boolean failed = false;
+        boolean result = false;
+        File f = new File(System.getProperty("test.dir", "."),
+                          "print-writer.out");
+        f.deleteOnExit();
+
+        for (OpsAfterClose op : OpsAfterClose.values()) {
+            PrintWriter pw = new PrintWriter(
+                                new FileWriter(f));
+            pw.close();
+            result = op.check(pw);
+            if (!result) {
+                failed = true;
+            }
+           System.out.println(op + ":" + result);
+        }
+        if (failed) {
+            throw new Exception(
+                "Test failed for the failed operation{s} " +
+                "above for the PrintWriter");
+        }
+    }
+}
diff --git a/test/java/io/PrintWriter/OversynchronizedTest.java b/test/java/io/PrintWriter/OversynchronizedTest.java
new file mode 100644
index 0000000..f95decf
--- /dev/null
+++ b/test/java/io/PrintWriter/OversynchronizedTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @bug 4905777
+   @summary PrintWriter.println(Object) oversynchronized, can deadlock
+*/
+
+import java.io.PrintWriter;
+
+public class OversynchronizedTest extends Thread {
+    private static PrintWriter writer = new PrintWriter(System.out);
+    private static TestObj testObj = new TestObj("This is a test.", writer);
+    private static int loopNum = 100;
+
+    public void run() {
+        for(int i=0; i<loopNum; i++) {
+            testObj.test();
+
+            //passing an object to PrintWriter.println might cause deadlock
+            //if the object has a synchronized toString() method.
+            //using PrintWriter.println(testObj.toString()) won't have a problem
+           writer.println(testObj);
+        }
+    }
+
+    public static void main(String args[]) throws Exception {
+        // should no NullPointerException
+        writer.println((Object)null);
+
+        int num = 5;
+
+        OversynchronizedTest[] t = new OversynchronizedTest[num];
+        for(int i=0; i<num; i++) {
+            t[i] = new OversynchronizedTest();
+            t[i].start();
+        }
+
+        for(int i=0; i <num; i++) {
+            t[i].join();
+        }
+
+        System.out.println("Test completed");
+    }
+}
+
+class TestObj {
+    String mStr;
+
+    TestObj(String str, PrintWriter writer) {
+        mStr = str;
+        this.writer = writer;
+    }
+
+    synchronized void test() {
+        try {
+            long t = Math.round(Math.random()*10);
+            Thread.currentThread().sleep(t);
+        } catch (InterruptedException e) {
+            // jtreg timeout?
+            // Only jtreg will interrupt this thread so it knows what to do:
+            e.printStackTrace();
+        }
+
+        //the following line might cause hang if there is PrintWriter.println(testObj)
+        //called by other threads.
+        writer.println("In test().");
+    }
+
+    synchronized public String toString() {
+        writer.println("Calling toString\n");
+        return mStr;
+    }
+
+    private PrintWriter writer;
+}
diff --git a/test/java/io/PrintWriter/SubClass.java b/test/java/io/PrintWriter/SubClass.java
new file mode 100644
index 0000000..c2d9537
--- /dev/null
+++ b/test/java/io/PrintWriter/SubClass.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/* @test
+   @bug 4103356 4121985
+   @summary Test new subclassing features of PrintWriter
+ */
+
+import java.io.*;
+
+
+public class SubClass {
+
+
+    static class PW extends PrintWriter {
+
+        PW(Writer out) {
+            super(out);
+        }
+
+        public void println() {
+            try {
+                out.write("[EOL]");
+            } catch (IOException x) {
+                setError();
+            }
+            super.println();
+        }
+
+    }
+
+
+    public static void main(String[] args) throws Exception {
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PW(sw);
+        pw.println("Hello");
+        pw.close();
+        String s = sw.toString();
+        System.err.print(s);
+        if (!s.equals("Hello[EOL]" + System.getProperty("line.separator")))
+            throw new Exception("Subclass broken");
+    }
+
+}