[cp-patches] [PATCH] Fix PrintStream constructor API differences for null

Dr Andrew John Hughes gnu_andrew at member.fsf.org
Sun Jan 23 12:50:01 UTC 2011


On 23 January 2011 12:41, Pekka Enberg <penberg at kernel.org> wrote:
> 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 <penberg at 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 <penberg at 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
>
>
>
>

Ok to commit.
-- 
Andrew :-)

Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)

Support Free Java!
Contribute to GNU Classpath and the OpenJDK
http://www.gnu.org/software/classpath
http://openjdk.java.net

PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint: F8EF F1EA 401E 2E60 15FA  7927 142C 2591 94EF D9D8



More information about the Classpath-patches mailing list