7034155: (ch) NullPointerException in sun.io.ch.IOUtil when OOM is thrown
Rémi Forax
forax at univ-mlv.fr
Wed Apr 6 05:42:54 PDT 2011
On 04/06/2011 12:21 PM, Alan Bateman wrote:
>
> A bug report was submitted with the following stack trace:
>
> java.lang.NullPointerException
> at sun.nio.ch.Util.free(Util.java:199)
> at sun.nio.ch.Util.offerFirstTemporaryDirectBuffer(Util.java:176)
> at sun.nio.ch.IOUtil.read(IOUtil.java:181)
> at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:243)
>
> The NPE arises with code such as following when it's not possible to
> allocate a temporary direct buffer :
>
> ByteBuffer bb = null;
> try {
> bb = Util.getTemporaryDirectBuffer(...);
> :
> } finally {
> Util.releaseTemporaryDirectBuffer(bb);
> }
>
> Trivially fixed by changing this to:
>
>
> ByteBuffer bb = Util.getTemporaryDirectBuffer(...);
> try {
> :
> } finally {
> Util.releaseTemporaryDirectBuffer(bb);
> }
>
> An alternative would have been to change the Util methods to check for
> null, which is how it was handled originally.
>
> While changing DatagramChannelImpl I noticed that the exception thrown
> by the join is a bit confusing so I fixed that too.
>
> The webrev with the changes is here:
>
> http://cr.openjdk.java.net/~alanb/7034155/webrev/
>
> Thanks,
> Alan.
Hi Alan,
patch looks fine,
just nitpicking, in innerJoin, the second exception message can be
misleading if
the socket use a proprietary protocol which is not IPV4 (a non
StandardProtocolFamily).
So I propose to change:
"IPv4 socket cannot join IPv6 multicast group"
to:
"non IPv6 socket cannot join IPv6 multicast group"
cheers,
Rémi
More information about the nio-dev
mailing list