You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "garydgregory (via GitHub)" <gi...@apache.org> on 2025/11/17 15:04:21 UTC

[PR] ClassUtils now throws `IllegalArgumentException` when array is greater than JVM spec limit (255) [commons-lang]

garydgregory opened a new pull request, #1494:
URL: https://github.com/apache/commons-lang/pull/1494

   ClassUtils now throws `IllegalArgumentException` if a class name represents an array with more dimensions than the JVM spec allow, `255`
   
   Affects ClassUtils methods:
   
   - getClass(ClassLoader, String, boolean),
   - ClassUtils.getClass(ClassLoader, String),
   - ClassUtils.getClass(String, boolean),
   - ClassUtils.getClass(String)
   
   
   - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
   - [x] Read the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) if you use Artificial Intelligence (AI).
   - [ ] I used AI to create any part of, or all of, this pull request.
   - [x] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself.
   - [x] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
   - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   - [x] Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.
   


-- 
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: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ClassUtils now throws `IllegalArgumentException` when array is greater than JVM spec limit (255) [commons-lang]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #1494:
URL: https://github.com/apache/commons-lang/pull/1494#discussion_r2538260904


##########
src/main/java/org/apache/commons/lang3/ClassUtils.java:
##########
@@ -520,11 +527,12 @@ private static String getCanonicalName(final String name) {
      * supports the syntaxes "{@code java.util.Map.Entry[]}", "{@code java.util.Map$Entry[]}",
      * "{@code [Ljava.util.Map.Entry;}", and "{@code [Ljava.util.Map$Entry;}".
      *
-     * @param classLoader the class loader to use to load the class
-     * @param className the class name
-     * @return the class represented by {@code className} using the {@code classLoader}
-     * @throws NullPointerException if the className is null
-     * @throws ClassNotFoundException if the class is not found
+     * @param classLoader the class loader to use to load the class.
+     * @param className the class name.
+     * @return the class represented by {@code className} using the {@code classLoader}.
+     * @throws NullPointerException if the className is null.
+     * @throws ClassNotFoundException if the class is not found.
+     * @throws IllegalArgumentException Thrown if the class name represents an array with more dimensions than the JVM supports, 255.

Review Comment:
   Hm, probably not, because `IllegalArgumentException` is _only_ thrown if the array dimensions are illegal. I'll improve the Javadocs by adding a reference to `Class#forName()`.



-- 
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: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ClassUtils now throws `IllegalArgumentException` when array is greater than JVM spec limit (255) [commons-lang]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #1494:
URL: https://github.com/apache/commons-lang/pull/1494#issuecomment-3547856847

   Note that the macos java 8 failure is due to the current Cloudfare downtime/DoS/something...


-- 
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: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ClassUtils now throws `IllegalArgumentException` when array is greater than JVM spec limit (255) [commons-lang]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #1494:
URL: https://github.com/apache/commons-lang/pull/1494#discussion_r2537968253


##########
src/main/java/org/apache/commons/lang3/ClassUtils.java:
##########
@@ -48,6 +48,8 @@
  */
 public class ClassUtils {
 
+    private static final int MAX_JVM_ARRAY_DIMENSION = 255;

Review Comment:
   OK & done.



-- 
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: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ClassUtils now throws `IllegalArgumentException` when array is greater than JVM spec limit (255) [commons-lang]

Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on code in PR #1494:
URL: https://github.com/apache/commons-lang/pull/1494#discussion_r2538158344


##########
src/main/java/org/apache/commons/lang3/ClassUtils.java:
##########
@@ -520,11 +527,12 @@ private static String getCanonicalName(final String name) {
      * supports the syntaxes "{@code java.util.Map.Entry[]}", "{@code java.util.Map$Entry[]}",
      * "{@code [Ljava.util.Map.Entry;}", and "{@code [Ljava.util.Map$Entry;}".
      *
-     * @param classLoader the class loader to use to load the class
-     * @param className the class name
-     * @return the class represented by {@code className} using the {@code classLoader}
-     * @throws NullPointerException if the className is null
-     * @throws ClassNotFoundException if the class is not found
+     * @param classLoader the class loader to use to load the class.
+     * @param className the class name.
+     * @return the class represented by {@code className} using the {@code classLoader}.
+     * @throws NullPointerException if the className is null.
+     * @throws ClassNotFoundException if the class is not found.
+     * @throws IllegalArgumentException Thrown if the class name represents an array with more dimensions than the JVM supports, 255.

Review Comment:
   Should we be more generic here and say that `IllegalArgumentException` is thrown if the `className` is syntactically invalid (it does not follow neither the syntax in [JLS 6.7](https://docs.oracle.com/javase/specs/jls/se25/html/jls-6.html#jls-6.7), [JLS 13.1](https://docs.oracle.com/javase/specs/jls/se25/html/jls-13.html#jls-13.1) nor the array type representation used by `Class.getName()`) **or** it does not respect the length and nesting limits imposed by JVMS?



-- 
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: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ClassUtils now throws `IllegalArgumentException` when array is greater than JVM spec limit (255) [commons-lang]

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory merged PR #1494:
URL: https://github.com/apache/commons-lang/pull/1494


-- 
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: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] ClassUtils now throws `IllegalArgumentException` when array is greater than JVM spec limit (255) [commons-lang]

Posted by "raboof (via GitHub)" <gi...@apache.org>.
raboof commented on code in PR #1494:
URL: https://github.com/apache/commons-lang/pull/1494#discussion_r2537791113


##########
src/main/java/org/apache/commons/lang3/ClassUtils.java:
##########
@@ -48,6 +48,8 @@
  */
 public class ClassUtils {
 
+    private static final int MAX_JVM_ARRAY_DIMENSION = 255;

Review Comment:
   maybe link to https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.1 / https://docs.oracle.com/javase/specs/jvms/se25/html/jvms-4.html#jvms-4.4.1 ?



-- 
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: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org