cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 28646] New: - JXPathMetaModule null pointer exception.
Date Wed, 28 Apr 2004 02:46:39 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=28646>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=28646

JXPathMetaModule null pointer exception.

           Summary: JXPathMetaModule null pointer exception.
           Product: Cocoon 2
           Version: 2.1.4
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: general components
        AssignedTo: dev@cocoon.apache.org
        ReportedBy: andrzej@chaeron.com


The 2.1.4 version of the JXPathMetaModule will throw a null pointer exception, 
catch it and then rethrow it as a ConfigurationException if you try to access a 
non-existing item specified by an xpath expression, even if the lenient setting 
is true.

In getAttributeValues() there is a statement that looks like:

if (i.hasNext()) { values = new LinkedList(); }

which tests if the iterator has any values. However if the xpath expression did 
not match, then there will be NO values (ie. the hasNext() will fail), and the 
values variable stays set to a null value.

The problem is that then a few lines later the code does a:

obj = values.toArray();

which triggers the null pointer exception which then is caught further down and 
incorrectly rethrown as the ConfigurationException.

The simple solution is to eliminate the "if" around the 

values = new LinkedList();

There are more effient methods that can also be used to fix this problem if you 
don't want to create the LinkedList() in the situation where there are no 
matching xpath values such as the following code snippet:

Iterator i = jxContext.iterate(name);
if (i.hasNext()) { 
   values = new LinkedList(); 
   while (i.hasNext()) {
      values.add(i.next());
   }
   obj = values.toArray();
   if (obj.length == 0) { obj = null; }
} else {
   obj = null;
}

Be nice to get this fixed for 2.1.5.

Thanks!

....Andrzej

Mime
View raw message