[
https://issues.apache.org/jira/browse/LANG-1771?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18011340#comment-18011340
]
Yudan Liu commented on LANG-1771:
---------------------------------
You're right to raise concerns about the behavior of
{{{}ClassUtils.getShortCanonicalName{}}}, but I believe the test input used in
this case — {{"[String"}} — is not a valid canonical or internal JVM class name.
In the JVM, the internal name for a one-dimensional array of {{String}} is
{{{}"[Ljava.lang.String;"{}}}. The input {{"[String"}} is malformed and doesn't
conform to any expected format (neither canonical nor internal JVM type
descriptors).
While {{[String}} is invalid, the method should not silently return
{{{}short[]{}}}. Instead it should validate input and either throw an exception
or fail-safe return, to avoid misleading outputs.
> Incorrect output from ClassUtils.getCanonicalName when input is "[String" in
> version 3.18.0-SNAPSHOT
> -----------------------------------------------------------------------------------------------------
>
> Key: LANG-1771
> URL: https://issues.apache.org/jira/browse/LANG-1771
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.*
> Affects Versions: 3.18.0
> Environment: MacOS Sequoia Version 15.3.2
> JDK 8
>
> Reporter: IlikeCode
> Priority: Major
> Attachments: Screenshot 2025-05-20 at 2.23.16 am.png
>
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> In org.apache.commons.lang3.ClassUtils, the method "public static String
> getShortCanonicalName(final String canonicalName)" returns an incorrect
> result when given certain malformed array class name strings. Specifically,
> for the input {{{}"[String"{}}}, it incorrectly returns {{"short[]"}} instead
> of the expected {{{}"String[]"{}}}.
>
> Test Code
> {code:java}
> package org.apache.commons.lang3;
> import org.junit.jupiter.api.Test;
> import static org.junit.jupiter.api.Assertions.assertEquals;
> public class ClassUtilsGetCanonicalName {
> @Test
> public void testGetCanonicalName() {
> // Test case: Non-empty string with one array dimension
> String input = "[String";
> String expectedOutput = "String[]";
> String actualOutput = ClassUtils.getShortCanonicalName(input);
> assertEquals(expectedOutput, actualOutput);
> }
> }
> {code}
> Expected Result: String[]
> Actual Result: short[]
--
This message was sent by Atlassian Jira
(v8.20.10#820010)