Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8259911: byteArrayViewVarHandle should throw ArrayIndexOutOfBoundsExc…
…eption

Reviewed-by: jvernee, mchung
  • Loading branch information
cl4es committed Jan 20, 2021
1 parent 1f47de5 commit 27cc62a5c7fb249a932f22bc488643d64b1158ff
Showing with 534 additions and 521 deletions.
  1. +2 −2 src/java.base/share/classes/java/lang/invoke/MethodHandles.java
  2. +7 −2 src/java.base/share/classes/java/lang/invoke/X-VarHandleByteArrayView.java.template
  3. +9 −1 test/jdk/java/lang/invoke/VarHandles/VarHandleBaseTest.java
  4. +29 −29 test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessBoolean.java
  5. +32 −32 test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessByte.java
  6. +32 −32 test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessChar.java
  7. +23 −23 test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessDouble.java
  8. +23 −23 test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessFloat.java
  9. +32 −32 test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessInt.java
  10. +32 −32 test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessLong.java
  11. +32 −32 test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessShort.java
  12. +20 −20 test/jdk/java/lang/invoke/VarHandles/VarHandleTestAccessString.java
  13. +9 −9 test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsChar.java
  14. +20 −20 test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsDouble.java
  15. +20 −20 test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java
  16. +32 −32 test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsInt.java
  17. +32 −32 test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsLong.java
  18. +9 −9 test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsShort.java
  19. +7 −7 test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessBoolean.java
  20. +8 −8 test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessByte.java
  21. +8 −8 test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessChar.java
  22. +7 −7 test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessDouble.java
  23. +7 −7 test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessFloat.java
  24. +8 −8 test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessInt.java
  25. +8 −8 test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessLong.java
  26. +8 −8 test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessShort.java
  27. +6 −6 test/jdk/java/lang/invoke/VarHandles/VarHandleTestMethodHandleAccessString.java
  28. +32 −32 test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template
  29. +32 −32 test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template
  30. +8 −8 test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestMethodHandleAccess.java.template
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -4371,7 +4371,7 @@ public static VarHandle arrayElementVarHandle(Class<?> arrayClass) throws Illega
* {@code double}.
* <p>
* Access of bytes at a given index will result in an
* {@code IndexOutOfBoundsException} if the index is less than {@code 0}
* {@code ArrayIndexOutOfBoundsException} if the index is less than {@code 0}
* or greater than the {@code byte[]} array length minus the size (in bytes)
* of {@code T}.
* <p>
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -35,7 +35,9 @@ import jdk.internal.vm.annotation.ForceInline;

import java.nio.ByteBuffer;
import java.nio.ReadOnlyBufferException;
import java.util.List;
import java.util.Objects;
import java.util.function.BiFunction;

import static java.lang.invoke.MethodHandleStatics.UNSAFE;

@@ -107,9 +109,12 @@ final class VarHandleByteArrayAs$Type$s extends VarHandleByteArrayBase {
return at.accessModeType(byte[].class, $type$.class, int.class);
}

private static final BiFunction<String, List<Number>, ArrayIndexOutOfBoundsException>
OOBEF = Preconditions.outOfBoundsExceptionFormatter(ArrayIndexOutOfBoundsException::new);

@ForceInline
static int index(byte[] ba, int index) {
return Preconditions.checkIndex(index, ba.length - ALIGN, null);
return Preconditions.checkIndex(index, ba.length - ALIGN, OOBEF);
}

@ForceInline
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -70,6 +70,14 @@ static void checkIOOBE(Object message, ThrowingRunnable r) {
checkWithThrowable(IndexOutOfBoundsException.class, message, r);
}

static void checkAIOOBE(ThrowingRunnable r) {
checkWithThrowable(ArrayIndexOutOfBoundsException.class, null, r);
}

static void checkAIOOBE(Object message, ThrowingRunnable r) {
checkWithThrowable(ArrayIndexOutOfBoundsException.class, message, r);
}

static void checkASE(ThrowingRunnable r) {
checkWithThrowable(ArrayStoreException.class, null, r);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -1204,116 +1204,116 @@ static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
final int ci = i;

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean x = (boolean) vh.get(array, ci);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
vh.set(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean x = (boolean) vh.getVolatile(array, ci);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
vh.setVolatile(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean x = (boolean) vh.getAcquire(array, ci);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
vh.setRelease(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean x = (boolean) vh.getOpaque(array, ci);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
vh.setOpaque(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean r = vh.compareAndSet(array, ci, true, false);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean r = (boolean) vh.compareAndExchange(array, ci, false, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean r = (boolean) vh.compareAndExchangeAcquire(array, ci, false, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean r = (boolean) vh.compareAndExchangeRelease(array, ci, false, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean r = vh.weakCompareAndSetPlain(array, ci, true, false);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean r = vh.weakCompareAndSet(array, ci, true, false);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, true, false);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, ci, true, false);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean o = (boolean) vh.getAndSet(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean o = (boolean) vh.getAndSetAcquire(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean o = (boolean) vh.getAndSetRelease(array, ci, true);
});


checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean o = (boolean) vh.getAndBitwiseOr(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean o = (boolean) vh.getAndBitwiseOrAcquire(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean o = (boolean) vh.getAndBitwiseOrRelease(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean o = (boolean) vh.getAndBitwiseAnd(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean o = (boolean) vh.getAndBitwiseAndAcquire(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean o = (boolean) vh.getAndBitwiseAndRelease(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean o = (boolean) vh.getAndBitwiseXor(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean o = (boolean) vh.getAndBitwiseXorAcquire(array, ci, true);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean o = (boolean) vh.getAndBitwiseXorRelease(array, ci, true);
});
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -1230,127 +1230,127 @@ static void testArrayIndexOutOfBounds(VarHandle vh) throws Throwable {
for (int i : new int[]{-1, Integer.MIN_VALUE, 10, 11, Integer.MAX_VALUE}) {
final int ci = i;

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte x = (byte) vh.get(array, ci);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
vh.set(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte x = (byte) vh.getVolatile(array, ci);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
vh.setVolatile(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte x = (byte) vh.getAcquire(array, ci);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
vh.setRelease(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte x = (byte) vh.getOpaque(array, ci);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
vh.setOpaque(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean r = vh.compareAndSet(array, ci, (byte)0x01, (byte)0x23);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte r = (byte) vh.compareAndExchange(array, ci, (byte)0x23, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte r = (byte) vh.compareAndExchangeAcquire(array, ci, (byte)0x23, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte r = (byte) vh.compareAndExchangeRelease(array, ci, (byte)0x23, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean r = vh.weakCompareAndSetPlain(array, ci, (byte)0x01, (byte)0x23);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean r = vh.weakCompareAndSet(array, ci, (byte)0x01, (byte)0x23);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean r = vh.weakCompareAndSetAcquire(array, ci, (byte)0x01, (byte)0x23);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
boolean r = vh.weakCompareAndSetRelease(array, ci, (byte)0x01, (byte)0x23);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndSet(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndSetAcquire(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndSetRelease(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndAdd(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndAddAcquire(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndAddRelease(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndBitwiseOr(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndBitwiseOrAcquire(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndBitwiseOrRelease(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndBitwiseAnd(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndBitwiseAndAcquire(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndBitwiseAndRelease(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndBitwiseXor(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndBitwiseXorAcquire(array, ci, (byte)0x01);
});

checkIOOBE(() -> {
checkAIOOBE(() -> {
byte o = (byte) vh.getAndBitwiseXorRelease(array, ci, (byte)0x01);
});
}

0 comments on commit 27cc62a

Please sign in to comment.