Ensure IovArray is usuable without sun.misc.Unsafe (#10870)

Motivation:

https://github.com/netty/netty/pull/10814 did fix a bug where we did try to call memoryAddress() even tho this is not supported. Unfortunally this fix was only applied for one method and so we missed another method which then could throw an exception when we called memoryAddress()

Modifications:

- Also fix the memoryAddress(offset) method.
_ Adjust unit test to also test this.

Result:

Fixes https://github.com/netty/netty/issues/10813 completely.
This commit is contained in:
Norman Maurer 2020-12-16 20:46:19 +01:00 committed by GitHub
parent 8ea0d8f41a
commit 882c111568
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -23,6 +23,7 @@ import io.netty.channel.unix.IovArray;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public abstract class IovArrayTest { public abstract class IovArrayTest {
@ -40,6 +41,7 @@ public abstract class IovArrayTest {
assertEquals(16, array.size()); assertEquals(16, array.size());
assertTrue(buf.release()); assertTrue(buf.release());
assertTrue(buf2.release()); assertTrue(buf2.release());
assertNotEquals(-1, array.memoryAddress(0));
array.release(); array.release();
assertEquals(0, buffer.refCnt()); assertEquals(0, buffer.refCnt());
} }

View File

@ -212,7 +212,7 @@ public final class IovArray implements MessageProcessor {
* Returns the {@code memoryAddress} for the given {@code offset}. * Returns the {@code memoryAddress} for the given {@code offset}.
*/ */
public long memoryAddress(int offset) { public long memoryAddress(int offset) {
return memory.memoryAddress() + idx(offset); return memoryAddress + idx(offset);
} }
/** /**