0

An app gets the following exception occasionally:

Stack trace:

java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.OutputStream.write(byte[], int, int)' on a null object reference
    at java.io.BufferedOutputStream.flushInternal(BufferedOutputStream.java:185)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:85)

from:

bufferedOutputStream.flush()

I assume it is not because bufferedOutputStream is null, but something else. If may understanding correct? If so, what is it?

bufferedOutputStream.write(byteArrayData, iOffset, iDataLength);
bufferedOutputStream.flush();
Hong
  • 17,643
  • 21
  • 81
  • 142
  • 1
    How are you creating `bufferedOutputStream`? It would appear that whatever `OutputStream` you are supplying to the `BufferedOutputStream` constructor is `null`. – CommonsWare Jul 16 '19 at 22:41
  • It is created like this: new BufferedOutputStream(outputStream). I will check outputStream and report back. It may take a while because it happens only occasionally. – Hong Jul 16 '19 at 22:51
  • So `outputStream` is null only occasionally. Duplicate. – user207421 Jul 17 '19 at 04:45
  • I am yet to confirm it. It would be a bit surprising if BufferedOutputStream takes a null OutoutStream in its constructor without throwing an exception. – Hong Jul 17 '19 at 11:03

0 Answers0