mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8283075: Bad IllegalArgumentException message for out of range rank from ClassDesc.arrayType(int)
Reviewed-by: vromero, alanb
This commit is contained in:
parent
12dca36c73
commit
32f8437d85
2 changed files with 35 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2022, 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
|
||||
|
@ -148,7 +148,8 @@ public sealed interface ClassDesc
|
|||
* is described by this {@linkplain ClassDesc}.
|
||||
*
|
||||
* @return a {@linkplain ClassDesc} describing the array type
|
||||
* @throws IllegalStateException if the resulting {@linkplain ClassDesc} would have an array rank of greater than 255
|
||||
* @throws IllegalStateException if the resulting {@linkplain
|
||||
* ClassDesc} would have an array rank of greater than 255
|
||||
* @jvms 4.4.1 The CONSTANT_Class_info Structure
|
||||
*/
|
||||
default ClassDesc arrayType() {
|
||||
|
@ -167,14 +168,27 @@ public sealed interface ClassDesc
|
|||
*
|
||||
* @param rank the rank of the array
|
||||
* @return a {@linkplain ClassDesc} describing the array type
|
||||
* @throws IllegalArgumentException if the rank is less than or equal to zero or if the rank of the resulting array type is
|
||||
* @throws IllegalArgumentException if the rank is less than or
|
||||
* equal to zero or if the rank of the resulting array type is
|
||||
* greater than 255
|
||||
* @jvms 4.4.1 The CONSTANT_Class_info Structure
|
||||
*/
|
||||
default ClassDesc arrayType(int rank) {
|
||||
int currentDepth = ConstantUtils.arrayDepth(descriptorString());
|
||||
if (rank <= 0 || currentDepth + rank > ConstantUtils.MAX_ARRAY_TYPE_DESC_DIMENSIONS)
|
||||
throw new IllegalArgumentException("rank: " + currentDepth + rank);
|
||||
int netRank;
|
||||
if (rank <= 0) {
|
||||
throw new IllegalArgumentException("rank " + rank + " is not a positive value");
|
||||
}
|
||||
try {
|
||||
int currentDepth = ConstantUtils.arrayDepth(descriptorString());
|
||||
netRank = Math.addExact(currentDepth, rank);
|
||||
if (netRank > ConstantUtils.MAX_ARRAY_TYPE_DESC_DIMENSIONS) {
|
||||
throw new IllegalArgumentException("rank: " + netRank +
|
||||
" exceeds maximum supported dimension of " +
|
||||
ConstantUtils.MAX_ARRAY_TYPE_DESC_DIMENSIONS);
|
||||
}
|
||||
} catch (ArithmeticException ae) {
|
||||
throw new IllegalArgumentException("Integer overflow in rank computation");
|
||||
}
|
||||
return ClassDesc.ofDescriptor("[".repeat(rank) + descriptorString());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue