Snappy.compress declares to throw IOException but does not throw any. #26

Closed
tkowalcz opened this Issue Mar 22, 2013 · 2 comments

Projects

None yet

2 participants

@tkowalcz

Snappy.compress method declaration includes "throws IOException". Implementation just calls rawCompress() that does not throw IOException so this throws is not needed.

It makes sense that when operating on in memory byte array there is no place to throw IOException.

@xerial
Owner

It looks like I forgot to add throws IOException statement in rawCompress.

In the native code (SnappyNative.cpp), there is a possibility that it throws IOException when an invalid object is passed to this API.

@xerial
Owner

It would be a corner case, but rawCompress uses GetPrimitiveArrayCritical in JNI, and it would throw when arrays must be copied to somewhere in JVM heap but sufficient amount of memory is not available.
http://docs.oracle.com/javase/6/docs/technotes/guides/jni/spec/functions.html#GetPrimitiveArrayCritical

Oracle JDK and OpenJDK never create copies of arrays in GetPrimitiveArrayCritical, so this error never happens. The other JVM implementation might have different behavior.

@xerial xerial closed this in 64c35c7 Mar 28, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment