aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-duplications
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2017-10-08 09:44:48 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2017-10-17 14:49:54 +0200
commit83321d24c812dc6a0eaa1d6240b665d15753d3d4 (patch)
tree0f30033b3e531572d2dab3865b817583378a59cc /sonar-duplications
parent0020b89d4510cca8f283e684e301c5abf1e1b5c3 (diff)
downloadsonarqube-83321d24c812dc6a0eaa1d6240b665d15753d3d4.tar.gz
sonarqube-83321d24c812dc6a0eaa1d6240b665d15753d3d4.zip
SONAR-9828 fix failure in CPD on Java 9
Diffstat (limited to 'sonar-duplications')
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java11
1 files changed, 10 insertions, 1 deletions
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java b/sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java
index 6468157d28c..a52a4e4ca88 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java
@@ -19,6 +19,7 @@
*/
package org.sonar.duplications.block;
+import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.Arrays;
@@ -88,7 +89,15 @@ public final class ByteArray {
int size = (bytes.length / 4) + (bytes.length % 4 == 0 ? 0 : 1);
ByteBuffer bb = ByteBuffer.allocate(size * 4);
bb.put(bytes);
- bb.rewind();
+ // see https://github.com/mongodb/mongo-java-driver/commit/21c91bd364d38489e0bbe2e390efdb3746ee3fff
+ // The Java 9 ByteBuffer classes introduces overloaded methods with covariant return types for the following methods used by the driver:
+// Without casting, exceptions like this are thrown when executing on Java 8 and lower:
+
+ // java.lang.NoSuchMethodError: java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer
+
+ //This is because the generated byte code includes the static return type of the method, which is not found on Java 8 and lower because
+ //the overloaded methods with covariant return types don't exist.
+ ((Buffer) bb).rewind();
IntBuffer ib = bb.asIntBuffer();
int[] result = new int[size];
ib.get(result);