Skip to content

Commit

Permalink
[netty#1852] Fix bug in UnpooledDirectByteBuf.nioBuffer(...) implemen…
Browse files Browse the repository at this point in the history
…tation
  • Loading branch information
Norman Maurer committed Sep 18, 2013
1 parent f034f90 commit c0bbde4
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ private ByteBuffer internalNioBuffer() {

@Override
public ByteBuffer nioBuffer(int index, int length) {
return (ByteBuffer) buffer.duplicate().position(index).position(index + length);
return (ByteBuffer) buffer.duplicate().position(index).limit(index + length);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class BigEndianDirectByteBufTest extends AbstractByteBufTest {

@Override
protected ByteBuf newBuffer(int length) {
buffer = Unpooled.directBuffer(length);
buffer = newDirectBuffer(length);
assertSame(ByteOrder.BIG_ENDIAN, buffer.order());
assertEquals(0, buffer.writerIndex());
return buffer;
Expand All @@ -38,4 +38,8 @@ protected ByteBuf newBuffer(int length) {
protected ByteBuf[] components() {
return new ByteBuf[] { buffer };
}

protected ByteBuf newDirectBuffer(int length) {
return new UnpooledDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, Integer.MAX_VALUE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.buffer;


import io.netty.util.internal.PlatformDependent;
import org.junit.Assume;
import org.junit.Before;

public class BigEndianUnsafeDirectByteBufTest extends BigEndianDirectByteBufTest {

@Before
public void checkHasUnsafe() {
Assume.assumeTrue("sun.misc.Unsafe not found, skip tests", PlatformDependent.hasUnsafe());
}

@Override
protected ByteBuf newBuffer(int length) {
return new UnpooledUnsafeDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, Integer.MAX_VALUE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class LittleEndianDirectByteBufTest extends AbstractByteBufTest {

@Override
protected ByteBuf newBuffer(int length) {
buffer = Unpooled.directBuffer(length).order(ByteOrder.LITTLE_ENDIAN);
buffer = newDirectBuffer(length).order(ByteOrder.LITTLE_ENDIAN);
assertSame(ByteOrder.LITTLE_ENDIAN, buffer.order());
assertEquals(0, buffer.writerIndex());
return buffer;
Expand All @@ -38,4 +38,8 @@ protected ByteBuf newBuffer(int length) {
protected ByteBuf[] components() {
return new ByteBuf[] { buffer };
}

protected ByteBuf newDirectBuffer(int length) {
return new UnpooledDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, Integer.MAX_VALUE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2013 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.buffer;

import io.netty.util.internal.PlatformDependent;
import org.junit.Assume;
import org.junit.Before;

public class LittleEndianUnsafeDirectByteBufTest extends LittleEndianDirectByteBufTest {

@Before
public void checkHasUnsafe() {
Assume.assumeTrue("sun.misc.Unsafe not found, skip tests", PlatformDependent.hasUnsafe());
}

@Override
protected ByteBuf newBuffer(int length) {
return new UnpooledUnsafeDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, Integer.MAX_VALUE);
}
}

0 comments on commit c0bbde4

Please sign in to comment.