Skip to content

Commit 73f5415

Browse files
committedJan 2, 2021
8258955: (bf) slice(int, int) on view buffers fails to adjust index according to primitive size
Reviewed-by: alanb
1 parent 881bceb commit 73f5415

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed
 

‎src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -237,7 +237,8 @@ class Direct$Type$Buffer$RW$$BO$
237237
0,
238238
length,
239239
length,
240-
index, segment);
240+
index << $LG_BYTES_PER_VALUE$,
241+
segment);
241242
}
242243

243244
public $Type$Buffer duplicate() {

‎test/jdk/java/nio/Buffer/ByteBufferViews.java

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323

2424
/* @test
2525
* @summary Binary data and view tests for byte buffers
26-
* @bug 8159257
26+
* @bug 8159257 8258955
2727
* @run testng ByteBufferViews
2828
*/
2929

@@ -174,6 +174,11 @@ public static Object[][] shortViewProvider() {
174174
bb -> bb.asShortBuffer()),
175175
Map.entry("bb.asShortBuffer().slice()",
176176
bb -> bb.asShortBuffer().slice()),
177+
Map.entry("bb.asShortBuffer().slice(index,length)",
178+
bb -> { var sb = bb.asShortBuffer();
179+
sb = sb.slice(1, sb.limit() - 1);
180+
bb.position(bb.position() + 2);
181+
return sb; }),
177182
Map.entry("bb.asShortBuffer().slice().duplicate()",
178183
bb -> bb.asShortBuffer().slice().duplicate())
179184
);
@@ -273,6 +278,11 @@ public static Object[][] charViewProvider() {
273278
bb -> bb.asCharBuffer()),
274279
Map.entry("bb.asCharBuffer().slice()",
275280
bb -> bb.asCharBuffer().slice()),
281+
Map.entry("bb.asCharBuffer().slice(index,length)",
282+
bb -> { var cb = bb.asCharBuffer();
283+
cb = cb.slice(1, cb.limit() - 1);
284+
bb.position(bb.position() + 2);
285+
return cb; }),
276286
Map.entry("bb.asCharBuffer().slice().duplicate()",
277287
bb -> bb.asCharBuffer().slice().duplicate())
278288
);
@@ -365,6 +375,11 @@ public static Object[][] intViewProvider() {
365375
bb -> bb.asIntBuffer()),
366376
Map.entry("bb.asIntBuffer().slice()",
367377
bb -> bb.asIntBuffer().slice()),
378+
Map.entry("bb.asIntBuffer().slice(index,length)",
379+
bb -> { var ib = bb.asIntBuffer();
380+
ib = ib.slice(1, ib.limit() - 1);
381+
bb.position(bb.position() + 4);
382+
return ib; }),
368383
Map.entry("bb.asIntBuffer().slice().duplicate()",
369384
bb -> bb.asIntBuffer().slice().duplicate())
370385
);
@@ -467,6 +482,11 @@ public static Object[][] longViewProvider() {
467482
bb -> bb.asLongBuffer()),
468483
Map.entry("bb.asLongBuffer().slice()",
469484
bb -> bb.asLongBuffer().slice()),
485+
Map.entry("bb.asLongBuffer().slice(index,length)",
486+
bb -> { var lb = bb.asLongBuffer();
487+
lb = lb.slice(1, lb.limit() - 1);
488+
bb.position(bb.position() + 8);
489+
return lb; }),
470490
Map.entry("bb.asLongBuffer().slice().duplicate()",
471491
bb -> bb.asLongBuffer().slice().duplicate())
472492
);
@@ -575,6 +595,11 @@ public static Object[][] floatViewProvider() {
575595
bb -> bb.asFloatBuffer()),
576596
Map.entry("bb.asFloatBuffer().slice()",
577597
bb -> bb.asFloatBuffer().slice()),
598+
Map.entry("bb.asFloatBuffer().slice(index,length)",
599+
bb -> { var fb = bb.asFloatBuffer();
600+
fb = fb.slice(1, fb.limit() - 1);
601+
bb.position(bb.position() + 4);
602+
return fb; }),
578603
Map.entry("bb.asFloatBuffer().slice().duplicate()",
579604
bb -> bb.asFloatBuffer().slice().duplicate())
580605
);
@@ -668,6 +693,11 @@ public static Object[][] doubleViewProvider() {
668693
bb -> bb.asDoubleBuffer()),
669694
Map.entry("bb.asDoubleBuffer().slice()",
670695
bb -> bb.asDoubleBuffer().slice()),
696+
Map.entry("bb.asDoubleBuffer().slice(index,length)",
697+
bb -> { var db = bb.asDoubleBuffer();
698+
db = db.slice(1, db.limit() - 1);
699+
bb.position(bb.position() + 8);
700+
return db; }),
671701
Map.entry("bb.asDoubleBuffer().slice().duplicate()",
672702
bb -> bb.asDoubleBuffer().slice().duplicate())
673703
);

0 commit comments

Comments
 (0)
Please sign in to comment.