mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-06 03:35:10 +00:00
8357955: java.lang.classfile.Signature.ArrayTypeSig.of IAE not thrown for dims > 255
Reviewed-by: jlahoda
This commit is contained in:
parent
04e0fe00ab
commit
d43f588db1
@ -417,15 +417,18 @@ public sealed interface Signature {
|
||||
* {@return a signature for an array type}
|
||||
* @param dims the dimension of the array
|
||||
* @param componentSignature the component type
|
||||
* @throws IllegalArgumentException if the resulting array type exceeds
|
||||
* 255 dimensions
|
||||
* @throws IllegalArgumentException if {@code dims < 1} or the
|
||||
* resulting array type exceeds 255 dimensions
|
||||
*/
|
||||
public static ArrayTypeSig of(int dims, Signature componentSignature) {
|
||||
requireNonNull(componentSignature);
|
||||
if (componentSignature instanceof SignaturesImpl.ArrayTypeSigImpl arr) {
|
||||
if (dims < 1 || dims > 255 - arr.arrayDepth())
|
||||
throw new IllegalArgumentException("illegal array depth value");
|
||||
return new SignaturesImpl.ArrayTypeSigImpl(dims + arr.arrayDepth(), arr.elemType());
|
||||
}
|
||||
if (dims < 1 || dims > 255)
|
||||
throw new IllegalArgumentException("illegal array depth value");
|
||||
if (componentSignature instanceof SignaturesImpl.ArrayTypeSigImpl arr)
|
||||
return new SignaturesImpl.ArrayTypeSigImpl(dims + arr.arrayDepth(), arr.elemType());
|
||||
return new SignaturesImpl.ArrayTypeSigImpl(dims, componentSignature);
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
/*
|
||||
* @test
|
||||
* @summary Testing Signatures.
|
||||
* @bug 8321540 8319463
|
||||
* @bug 8321540 8319463 8357955
|
||||
* @run junit SignaturesTest
|
||||
*/
|
||||
import java.io.IOException;
|
||||
@ -300,6 +300,20 @@ class SignaturesTest {
|
||||
""".lines().forEach(assertThrows(MethodSignature::parseFrom));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArraySignatureLimits() {
|
||||
var sig = Signature.parseFrom("I");
|
||||
var arrSig = Signature.parseFrom("[I");
|
||||
for (int dim : List.of(256, -1, 0))
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> Signature.ArrayTypeSig.of(dim, sig));
|
||||
for (int dim : List.of(255, -1, 0))
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> Signature.ArrayTypeSig.of(dim, arrSig));
|
||||
for (int dim : List.of(255, 1))
|
||||
Signature.ArrayTypeSig.of(dim, sig);
|
||||
for (int dim : List.of(254, 1))
|
||||
Signature.ArrayTypeSig.of(dim, arrSig);
|
||||
}
|
||||
|
||||
private Consumer<String> assertThrows(Function<String, ?> parser) {
|
||||
return s -> Assertions.assertThrows(IllegalArgumentException.class, () -> parser.apply(s), s);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user