From 45c62feb5fbc6bc521ae9714a0ca30c263e68c0e Mon Sep 17 00:00:00 2001 From: Till Krullmann Date: Thu, 24 Sep 2020 10:53:15 +0200 Subject: [PATCH] DigestUtils: avoid calling ByteBuffer.clear because of possible JDK incompatibility fixes #34 --- .../gradle/plugins/helm/util/DigestUtils.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/unbrokendome/gradle/plugins/helm/util/DigestUtils.kt b/src/main/kotlin/org/unbrokendome/gradle/plugins/helm/util/DigestUtils.kt index 96d7a737..f10e852e 100644 --- a/src/main/kotlin/org/unbrokendome/gradle/plugins/helm/util/DigestUtils.kt +++ b/src/main/kotlin/org/unbrokendome/gradle/plugins/helm/util/DigestUtils.kt @@ -29,7 +29,7 @@ internal fun calculateDigest( while (true) { - buffer.clear() + buffer.safeClear() val bytesRead = channel.read(buffer) if (bytesRead == -1) { @@ -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. *