ppkarwasz commented on code in PR #1495:
URL: https://github.com/apache/commons-lang/pull/1495#discussion_r2539690472
##########
src/main/java/org/apache/commons/lang3/ClassUtils.java:
##########
@@ -1523,12 +1540,20 @@ public static Class<?> primitiveToWrapper(final
Class<?> cls) {
*
* @param className the class name.
* @return the converted name.
- * @throws NullPointerException if the className is null.
+ * @throws NullPointerException if the className is null.
* @throws IllegalArgumentException Thrown if the class name represents an
array with more dimensions than the JVM supports, 255.
+ * @throws IllegalArgumentException Thrown if the class name length is
greater than 65,535.
+ * @see <a
href="https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-4.4.1">JVM:
Array dimension limits in JVM Specification
+ * CONSTANT_Class_info</a>
+ * @see <a
href="https://docs.oracle.com/javase/specs/jls/se25/html/jls-6.html#jls-6.7">JLS:
Fully Qualified Names and Canonical Names</a>
+ * @see <a
href="https://docs.oracle.com/javase/specs/jls/se25/html/jls-13.html#jls-13.1">JLS:
The Form of a Binary</a>
*/
private static String toCanonicalName(final String className) {
String canonicalName = StringUtils.deleteWhitespace(className);
Objects.requireNonNull(canonicalName, "className");
+ if (canonicalName.length() > MAX_CLASS_NAME_LENGTH) {
Review Comment:
`MAX_JVM_ARRAY_DIMENSION` by itself seems too low as a cap for canonical
names.
For example, a deepest-possible array type (255 dimensions) has a field
descriptor of the form:
```
[...[L<class_name>;
```
In this case `<class_name>` may be as long as `MAX_CLASS_NAME_LENGTH − 255 −
2` characters. But its canonical name representation:
```
<class_name>[]...[]
```
adds `[]` for each dimension, meaning the canonical name can be as large as
`MAX_CLASS_NAME_LENGTH + 255 − 2`.
More conservatively we might assume that the JVM can handle arrays of up to
255 dimensions of **arbitrary** classes, in which case the limit should be
`MAX_CLASS_NAME_LENGTH + 2 * MAX_JVM_ARRAY_DIMENSION`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]