Author: coheigea
Date: Thu May 28 09:33:12 2015
New Revision: 1682183

URL: http://svn.apache.org/r1682183
Log:
NPE fix for BinarySecurity

Modified:
    
webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/BinarySecurity.java

Modified: 
webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/BinarySecurity.java
URL: 
http://svn.apache.org/viewvc/webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/BinarySecurity.java?rev=1682183&r1=1682182&r2=1682183&view=diff
==============================================================================
--- 
webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/BinarySecurity.java
 (original)
+++ 
webservices/wss4j/branches/2_0_x-fixes/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/token/BinarySecurity.java
 Thu May 28 09:33:12 2015
@@ -219,9 +219,25 @@ public class BinarySecurity {
      * 
      * @return the first text node.
      */
-    protected Text getFirstNode() {
+    private Text getFirstNode() {
         Node node = element.getFirstChild();
-        return node != null && Node.TEXT_NODE == node.getNodeType() ? (Text) 
node : null;
+        while (node != null && Node.TEXT_NODE != node.getNodeType()) {
+            node = node.getNextSibling();
+        }
+        if (node instanceof Text) {
+            return (Text)node;
+        }
+        
+        // Otherwise we have no Text child. Just remove the child nodes + add 
a new text node
+        node = element.getFirstChild();
+        while (node != null) {
+            Node nextNode = node.getNextSibling();
+            element.removeChild(node);
+            node = nextNode;
+        }
+        
+        Node textNode = element.getOwnerDocument().createTextNode("");
+        return (Text)element.appendChild(textNode);
     }
 
     /**


Reply via email to