We recently had a bug a NullPointerException was being thrown when consuming a stream.
java.lang.NullPointerException: {throwable0_message}
at java.base/java.io.OutputStream.write(OutputStream.java:124)
at com.palantir.example.MyStreamStore.loadSingleBlockToOutputStream(MyStreamStore.java:193)
at com.palantir.example.MyStreamStore.loadSingleBlockToOutputStream(MyStreamStore.java:75)
at com.palantir.atlasdb.stream.AbstractGenericStreamStore.loadNBlocksToOutputStream(AbstractGenericStreamStore.java:211)
at com.palantir.atlasdb.stream.AbstractGenericStreamStore$1.lambda$get$0(AbstractGenericStreamStore.java:135)
In this instance, we were attempting to consume a stream outside of the transaction where it was loaded. A subsequent transaction marked the stream as unused and we then failed to read a block from the stream, resulting in a NullPointerException thrown in OutputStream.write when we attempt to get the length of a null byte[].
This is clearly not a AtlasDB bug. But there are some changes we could make to the stream store to make it easier to diagnose these issues in the future:
Explicitly check if the block is not found and throw an exception with a message indicating that this is user error and why.
Re-throw caught exceptions with a descriptive error message instead of just logging. This ensures these errors are discoverable when the exception is ultimately consumed. Logging and re-throwing exceptions is an anti-pattern, we should do one or the other.
We recently had a bug a
NullPointerException
was being thrown when consuming a stream.In this instance, we were attempting to consume a stream outside of the transaction where it was loaded. A subsequent transaction marked the stream as unused and we then failed to read a block from the stream, resulting in a
NullPointerException
thrown inOutputStream.write
when we attempt to get the length of a nullbyte[]
.https://github.com/openjdk/jdk/blob/890adb6410dab4606a4f26a942aed02fb2f55387/src/java.base/share/classes/java/io/OutputStream.java#L124
This is clearly not a AtlasDB bug. But there are some changes we could make to the stream store to make it easier to diagnose these issues in the future: