commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 26594] New: - [lang] add getLength() method to ArrayUtils
Date Mon, 02 Feb 2004 10:16:13 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26594>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26594

[lang] add getLength() method to ArrayUtils

           Summary: [lang] add getLength() method to ArrayUtils
           Product: Commons
           Version: unspecified
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Lang
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: Maarten.Coene@qmedit.com


Hi,

I need a method to determine the length of an array which doesn't throw a NPE if
the array is null (this makes the java.lang.reflect.Array.getLength() method
unsuitable for me because it throws a NPE if array is null). 

Here is a possible implementation for an Object array:

public static int getLength(final Object[] array) {
    if (array == null) {
        return 0;
    } else {
        return array.length;
    }
}

or, maybe you can use Object which makes this method usable for primitive arrays
as well:

public static int getLength(final Object array) {
    if (array == null) {
        return 0;
    } else {
        return java.lang.reflect.Array.getLength(array);
    }
}

Can someone please add such a method ?

thanks,
Maarten

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message