Skip to content

Commit

Permalink
Merge pull request #79 from unbroken-dome/fix/34-bytebuffer-clear
Browse files Browse the repository at this point in the history
Avoid possible JDK incompatibility about ByteBuffer.clear
  • Loading branch information
tkrullmann authored Sep 24, 2020
2 parents 5d68da6 + 45c62fe commit 7e057a5
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal fun calculateDigest(

while (true) {

buffer.clear()
buffer.safeClear()

val bytesRead = channel.read(buffer)
if (bytesRead == -1) {
Expand All @@ -44,6 +44,16 @@ internal fun calculateDigest(
}


/**
* Avoid using ByteBuffer.clear because of a JDK incompatibility that might lead to a NoSuchMethodError
* when compiling with JDK > 8 and running with JDK 8.
*/
private fun ByteBuffer.safeClear() {
position(0)
limit(capacity())
}


/**
* Calculates a digest over the contents of a file.
*
Expand Down

0 comments on commit 7e057a5

Please sign in to comment.