monitorjbl / excel-streaming-reader

An easy-to-use implementation of a streaming Excel reader using Apache POI
Apache License 2.0
946 stars 343 forks source link

NPE in StreamingWorkbookReader.init(InputStream) exception handler #171

Open ms1111 opened 5 years ago

ms1111 commented 5 years ago

In StreamingWorkbookReader.init(InputStream), if there's a RuntimeException, f.delete() is called. f may be null at this point, giving a NullPointerException.

    try {
      f = writeInputStreamToFile(is, builder.getBufferSize());
...
    } catch(IOException e) {
      throw new ReadException("Unable to read input stream", e);
    } catch(RuntimeException e) {
      f.delete();   // <----
      throw e;
    }

This is pretty harmless, but it does hide the original exception. I suppose it just needs an if (f != null) guard.

monitorjbl commented 5 years ago

Good catch, we should definitely add a null guard there.