Ignore:
Timestamp:
2008-05-28T16:22:47+12:00 (16 years ago)
Author:
ak19
Message:

Attempted fix for trac bug ticket #225 - NullPointerException. Possibly n is null at some time, so need to check for that before trying n.getFirstChild(). Null is returned, which the caller GSXML.getNodeByPath() and its caller GS2BrowseAction.classifierBrowse() already check for.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/util/GSXML.java

    r15321 r15767  
    423423  /** returns the (first) child element with the given name */
    424424  public static Node getChildByTagName(Node n, String name) {
    425    
    426     Node child = n.getFirstChild();
    427     while (child!=null) {
    428       if (child.getNodeName().equals(name)) {
    429         return child;
    430       }
    431       child = child.getNextSibling();
    432     }
    433     return null; //not found
     425      if(n != null) { // this line is an attempted solution to the NullPointerException mentioned
     426      // in trac bug ticket #225. If n is null can't do n.getFirstChild() below. As per bug #225:
     427      // GSXML.getNodeByPath() is called by GS2BrowseAction, which then calls this method.
     428      // If n is null, null will be returned which GS2BrowseAction already checks for. It's here
     429      // that the NullPointerException was thrown.
     430 
     431      Node child = n.getFirstChild();
     432      while (child!=null) {
     433          if (child.getNodeName().equals(name)) {
     434          return child;
     435          }
     436          child = child.getNextSibling();
     437      }
     438      }
     439      return null; //not found
    434440  }
    435441 
Note: See TracChangeset for help on using the changeset viewer.