You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "mark juchems (JIRA)" <ji...@apache.org> on 2009/09/22 21:54:16 UTC

[jira] Created: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
----------------------------------------------------------------------------------------------------

                 Key: LANG-535
                 URL: https://issues.apache.org/jira/browse/LANG-535
             Project: Commons Lang
          Issue Type: Bug
    Affects Versions: 2.4
         Environment: Java 1.4.2
            Reporter: mark juchems
            Priority: Minor


A semicolon is introduced into the class name at the end for all arrays...

String sArray[] = new String[2];
sArray[0] = "mark";
sArray[1] = "is cool";
String simpleString = "chris";
		
assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "mark juchems (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12759514#action_12759514 ] 

mark juchems edited comment on LANG-535 at 9/25/09 5:53 AM:
------------------------------------------------------------

So I put it all together in 1.5:

String sArray[] = new String[2];
sArray[0] = "mark";
sArray[1] = "is cool";
sArray.getClass().getSimpleName();

this returns:  String[]

I guess the java team has spoken.  I suggest deleting since 1.5 has an alternative...

 I still think I would rather have just the name and no brackets, however.   For my use I would have to do some additional editing.  I am sending in an Object[] or an Object into a method and need the same behavior for both.  

This failed when I sent in an array:

protected void createXML(XStream xStream, PrintWriter pw, Object o) {
		pw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
		xStream.alias(ClassUtils.getShortClassName(o, null), o.getClass());
		xStream.toXML(o, pw);
}

So I changed it to this:

protected void createXML(XStream xStream, PrintWriter pw, Object o, Class c) {
		pw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
		xStream.alias(ClassUtils.getShortClassName(c), c);
		xStream.toXML(o, pw);
}

Not a big change, but it is something..

      was (Author: mjuchems):
    So I put it all together in 1.5:

String sArray[] = new String[2];
sArray[0] = "mark";
sArray[1] = "is cool";
sArray.getClass().getSimpleName();

this returns:  String[]

I guess the java team has spoken.  I still think I would rather have just the name and no brackets, however.   For my use I would have to do some additional editing.

I suggest deleting since 1.5 has an alternative...
  
> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 3.0
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "Joerg Schaible (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12759158#action_12759158 ] 

Joerg Schaible commented on LANG-535:
-------------------------------------

Actually ClassUtils.getShortName should do what Class.getSimpleName does in JDK 1.5

> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 3.0
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Niall Pemberton updated LANG-535:
---------------------------------

    Fix Version/s:     (was: 3.0)
                   2.5

> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 2.5
>
>         Attachments: LANG-535.patch
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12764960#action_12764960 ] 

Henri Yandell commented on LANG-535:
------------------------------------

Difference in behaviour between JDK getSimpleName and Lang getShortClassName:

  JDK returns the class name for an inner class.
  Lang returns the surrounding class name and the class name of the inner class as the class name.

Difficult to say which is correct imo. Lang relies on '$' as the inner class name separator.

> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 3.0
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-535:
-------------------------------

    Attachment: LANG-535.patch

Attaching a patch that adds support for:

* arrays
* primitive arrays
* multiple dimension arrays
* Stops getPackageName using the underlying cls.getPackage().getName() after discovering java.lang.String[]'s getPackage to be null (at least within the Maven2/JUnit classloader).

Plus various tests.

> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: LANG-535.patch
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-535:
-------------------------------

         Fix Version/s: 3.0
    Remaining Estimate:     (was: 1h)
     Original Estimate:     (was: 1h)

> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 3.0
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12759355#action_12759355 ] 

Henri Yandell commented on LANG-535:
------------------------------------

Or it needs deleting if there is a JDK 1.5 alternative.

> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 3.0
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "mark juchems (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12759118#action_12759118 ] 

mark juchems commented on LANG-535:
-----------------------------------

Doing this in java :

String sArray[] = new String[2];
sArray[0] = "mark";
sArray[1] = "is cool";
String simpleString = "chris";

sArray.getClass() = "class [Ljava.lang.String;"

I am sure this is where they are going wrong.  I have not looked into the code, however, I would imagine they are taking everything past the last ".".

I am not sure what the correct return should be.  I know what I would like it to be, and that is apparent.  However, an "array" is a primitive data type and therefore not an Object,  so I believe it should throw and exception.  But that would not be helpful...


> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 3.0
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "mark juchems (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12759514#action_12759514 ] 

mark juchems commented on LANG-535:
-----------------------------------

So I put it all together in 1.5:

String sArray[] = new String[2];
sArray[0] = "mark";
sArray[1] = "is cool";
sArray.getClass().getSimpleName();

this returns:  String[]

I guess the java team has spoken.  I still think I would rather have just the name and no brackets, however.   For my use I would have to do some additional editing.

I suggest deleting since 1.5 has an alternative...

> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 3.0
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed LANG-535.
------------------------------

    Resolution: Fixed

 svn ci -m "Applying my patch from LANG-535 - adding support to getShortClassName and getPackageName for arrays, including primitive arrays and multi-dimensional arrays. Also stopped getPackageName relying on the underlying class.getPackage as it's sometimes null" src/test/org/apache/commons/lang/ClassUtilsTest.java src/java/org/apache/commons/lang/ClassUtils.java 
Sending        src/java/org/apache/commons/lang/ClassUtils.java
Sending        src/test/org/apache/commons/lang/ClassUtilsTest.java
Transmitting file data ..
Committed revision 825420.

> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: LANG-535.patch
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "Joerg Schaible (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12759519#action_12759519 ] 

Joerg Schaible commented on LANG-535:
-------------------------------------

In that case you could have written:

{code:java}
ClassUtils.getShortClassName(o.getClass().isArray() ? o.getClass().getComponentType() : o.getClass())
{code}

However, we're getting OT here. Come to the user's list of Commons, or for XStream specific questions to XStream's user's list ...

Cheers,
Jörg

> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 3.0
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12764972#action_12764972 ] 

Henri Yandell commented on LANG-535:
------------------------------------

Plus Lang provides a String API in addition to the Class API. Given that a Class may not be available, this isn't the same as say relying on the File API instead of Strings for IO work.

> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 3.0
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "Joerg Schaible (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12759401#action_12759401 ] 

Joerg Schaible commented on LANG-535:
-------------------------------------

Since 3.0 targets JDK 1.5 only - yes.

> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 3.0
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LANG-535) ClassUtils.getShortClassName() will not work with an array; it seems to add a semicolon to the end.

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12759012#action_12759012 ] 

Henri Yandell commented on LANG-535:
------------------------------------

I wonder if the package name equivalent is prefixed by '[' for arrays.

> ClassUtils.getShortClassName() will not work with an array;  it seems to add a semicolon to the end.
> ----------------------------------------------------------------------------------------------------
>
>                 Key: LANG-535
>                 URL: https://issues.apache.org/jira/browse/LANG-535
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.4
>         Environment: Java 1.4.2
>            Reporter: mark juchems
>            Priority: Minor
>             Fix For: 3.0
>
>
> A semicolon is introduced into the class name at the end for all arrays...
> String sArray[] = new String[2];
> sArray[0] = "mark";
> sArray[1] = "is cool";
> String simpleString = "chris";
> 		
> assertEquals("String", ClassUtils.getShortClassName(simpleString, null));
> assertEquals("String;", ClassUtils.getShortClassName(sArray, null));

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.