Hi, I recently ran into this:
sys::NullErr: java.lang.NullPointerException web::ChunkInStream.readBuf (WebUtil.fan:466) fan.sys.InStream.readAllBuf (InStream.java:170)
The (hidden) underlying cause was that the wrapped InStream was closed. But referring to the docs of InStream.readBuf() this shouldn't be a problem:
InStream
InStream.readBuf()
** Return null and leave buf's state untouched if end of stream. virtual Int? readBuf(Buf buf, Int n)
The ChunkInStream method in question looks like:
ChunkInStream
override Int? readBuf(Buf buf, Int n) { if (pushback != null && !pushback.isEmpty && n > 0) { buf.write(pushback.pop) return 1 } if (!checkChunk) return null numRead := in.readBuf(buf, chunkRem.min(n)) chunkRem -= numRead return numRead }
And the cause of the NullErr is in the last 3 lines:
NullErr
numRead := in.readBuf(buf, chunkRem.min(n)) chunkRem -= numRead return numRead
When the wrapped instream is closed, it correctly returns null which makes:
null
chunkRem -= numRead
throw the NullErr. A simple null check should solve the problem:
chunkRem -= numRead ?: 0
Cheers, Steve.
Good catch. That makes sense to me, I pushed a fix
Login or Signup to reply.
SlimerDude Thu 16 Oct 2014
Hi, I recently ran into this:
The (hidden) underlying cause was that the wrapped
InStream
was closed. But referring to the docs ofInStream.readBuf()
this shouldn't be a problem:The
ChunkInStream
method in question looks like:And the cause of the
NullErr
is in the last 3 lines:When the wrapped instream is closed, it correctly returns
null
which makes:throw the
NullErr
. A simple null check should solve the problem:Cheers, Steve.
brian Wed 22 Oct 2014
Good catch. That makes sense to me, I pushed a fix