Johan, I am not sure if this information is helpful but I will mention it anyway. We were receiving a null pointer exception in xpath-related code when we were verifying a signature. Our problem turned out to be that our app server was using a different version of some Xalan xpath classes. When we moved our xalan impl earlier in the classpath the problem went away. I hope that helps.
-Mark -----Original Message----- From: Johan Vanbockryck (jvanbock) [mailto:[EMAIL PROTECTED] Sent: Friday, March 12, 2004 5:00 AM To: [EMAIL PROTECTED] Subject: [Java] NullPointerException with XMLSignature transformations Hi, We're experiencing a NullPointerException when we try to sign an XML document when the transformations are being performed. We've been able to trace the cause of the problem, and are wondering if this is a bug in the XML signature code. What happens is: We use Axis with HTTP web services. Before the HTTP request is sent, an XML signature is created on some parts of the SOAP message that is being sent. We retrieve the XML document from the Axis message context, sign the XML and reassign the document to Axis. The problem is caused by XMLUtils class in the 'public static Document getOwnerDocument(Set xpathNodeSet)' method. In this method an iterator is retrieved from the Set and the owner of the first element retrieved from this iterator is returned as owner document. For some reason, there are some attribute nodes in the document we receive from Axis that have no owner document (I didn't know this was possible, but Axis appears to be able to do that). When the first is such an attribute, 'null' will be returned as owner document and this causes the exception at a later stage in the code. What we're wondering is if the method as it is now: public static Document getOwnerDocument(Set xpathNodeSet) { NullPointerException npe = null; Iterator iterator = xpathNodeSet.iterator(); while(iterator.hasNext()) { Node node = (Node) iterator.next(); if (node.getNodeType() == Node.DOCUMENT_NODE) { return (Document) node; } else { try { return node.getOwnerDocument(); } catch (NullPointerException e) { npe = e; } } } throw new NullPointerException(I18n.translate("endorsed.jdk1.4.0") + " Original message was \"" + (npe == null ? "" : npe.getMessage()) + "\""); } shouldn't be: public static Document getOwnerDocument(Set xpathNodeSet) { NullPointerException npe = null; Iterator iterator = xpathNodeSet.iterator(); while(iterator.hasNext()) { Node node = (Node) iterator.next(); if (node.getNodeType() == Node.DOCUMENT_NODE) { return (Document) node; } else { try { Document doc; doc = node.getOwnerDocument(); if (doc != null) return doc; } catch (NullPointerException e) { npe = e; } } } throw new NullPointerException(I18n.translate("endorsed.jdk1.4.0") + " Original message was \"" + (npe == null ? "" : npe.getMessage()) + "\""); } The usage of the while(iterator.hasNext()) would seem a bit redundant if it's only the first element is ever checked ... (as a side note, I'm using a CVS checkout from 2004-02-23) Regards, Johan
