classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] Patch: throw IOExceptions on closed PushbackInputStream


From: Mark Wielaard
Subject: Re: [cp-patches] Patch: throw IOExceptions on closed PushbackInputStream operations
Date: Thu, 15 Sep 2005 16:44:57 +0200

Hi,

On Wed, 2005-09-14 at 18:00 -0700, Anthony Green wrote:
> If you try an operation on a closed PushbackInputStream, you'll probably
> get a NullPointerException.  This patch turns them into IOExceptions
> with an appropriate message.  I think this is a better response based on
> the spec (any error should throw an IOException).
>
> 2005-09-14  Anthony Green  <address@hidden>
> 
>       * java/io/PushbackInputStream.java (available, read, skip): Handle
>       closed stream operations gracefully.

Yes, but please write the following part like all others with an if
statement at the start of the method:

>    public int available() throws IOException
>    {
> -    return (buf.length - pos) + super.available();
> +    try {
> +      return (buf.length - pos) + super.available();
> +    } catch (NullPointerException npe) {
> +      throw new IOException ("Stream closed");
> +    }
>    }

If you insist on writing it this way then please at least follow the
coding styleguide:
http://www.gnu.org/software/classpath/docs/hacking.html#SEC6

  try
    {
      return (buf.length - pos) + super.available();
    }
  catch (NullPointerException npe)
    {
      throw new IOException("Stream closed");
    }

Thanks,

Mark

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]