commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adrian Perez Jorge <>
Subject [JXPath] Why array range check exists in isCollectionElement() ?
Date Thu, 02 Dec 2004 17:33:49 GMT

why is there a range check?  Why is it necessary?

  My problem is this.  Suppose I have developed a Bean wich has an 
indexed property, and the real storage is, let say, an ArrayList:

  public class MyBean {

    ArrayList storage = new ArrayList();

    public String[] getStorage() {
       return storage.toArray(new String[] {} );

    public String getStorage(int i) {;

    public void setStorage(String[] storage) {;
        for (int i = 0; i < storage.length; ++i) {

    public void setStorage(int i, String str) {, str);

 When I call JXPathContext.getValue("storage[3]") it will do range 
check, so the ArrayList must be converted to an array each time I access 
to any of the elements.

 Is it possible to avoid range check and just catch and manage the 

 BTW, why range check is done for (xpath) indexes > 1?  If I do 
JXPathContext.getValue("storage[1]") it does not do range check, but for 
JXPathContext.getValue("storage[2]") it does not.  Why 1 is different?  
Think about an empty array.

  Thanks in advance,

Adrian P.J.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message