On Sun, 2011-01-23 at 00:36 +0000, Dr Andrew John Hughes wrote:
> What is the current behaviour?  Does it eventually throw an NPE but
> just performs a lot of additional computation first?  Or does it throw
> some other error?  Or return a bad value?
> 
> The NPEs should have some message as to what went wrong e.g. "The
> specified output stream was null.".

I've included an updated patch below.

                        Pekka

>From 264f44315ba45e1ecd95b5d6aee0ec8b7ce22db0 Mon Sep 17 00:00:00 2001
From: Pekka Enberg <penb...@kernel.org>
Date: Sat, 22 Jan 2011 18:19:08 +0200
Subject: [PATCH] Fix PrintStream constructor API differences for null

2011-01-22  Pekka Enberg <penb...@kernel.org>

        * java/io/PrintStream.java
        (PrintStream): Throw NullPointerException if out or encoding
        is null to be compatible with OpenJDK.
---
 java/io/PrintStream.java |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/java/io/PrintStream.java b/java/io/PrintStream.java
index eaab7c3..caa6035 100644
--- a/java/io/PrintStream.java
+++ b/java/io/PrintStream.java
@@ -181,10 +181,15 @@ public class PrintStream extends FilterOutputStream 
implements Appendable
    * @param out The <code>OutputStream</code> to write to.
    * @param auto_flush <code>true</code> to flush the stream after every
    * line, <code>false</code> otherwise
+   * @exception NullPointerException If out is null.
    */
   public PrintStream (OutputStream out, boolean auto_flush)
   {
     super (out);
+
+    if (out == null)
+      throw new NullPointerException("out is null");
+
     String encoding;
     try {
         encoding = SystemProperties.getProperty("file.encoding");
@@ -213,12 +218,19 @@ public class PrintStream extends FilterOutputStream 
implements Appendable
    * line, <code>false</code> otherwise
    * @param encoding The name of the character encoding to use for this
    * object.
+   * @exception NullPointerException If out or encoding is null.
    */
   public PrintStream (OutputStream out, boolean auto_flush, String encoding)
     throws UnsupportedEncodingException
   {
     super (out);
 
+    if (out == null)
+      throw new NullPointerException("out is null");
+
+    if (encoding == null)
+      throw new NullPointerException("encoding is null");
+
     new String(new byte[]{0}, encoding);    // check if encoding is supported
     this.encoding = encoding;
     this.auto_flush = auto_flush;
-- 
1.7.1




Reply via email to