Author: sebb
Date: Sat Apr 25 00:43:18 2009
New Revision: 768445

URL: http://svn.apache.org/viewvc?rev=768445&view=rev
Log:
Avoid NPE if XPath function does not match any nodes

Modified:
    
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathWrapper.java
    jakarta/jmeter/trunk/xdocs/changes.xml
    jakarta/jmeter/trunk/xdocs/usermanual/functions.xml

Modified: 
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathWrapper.java
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathWrapper.java?rev=768445&r1=768444&r2=768445&view=diff
==============================================================================
--- 
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathWrapper.java
 (original)
+++ 
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/XPathWrapper.java
 Sat Apr 25 00:43:18 2009
@@ -44,8 +44,11 @@
      * This Map serves two purposes:
      * - maps names to  containers
      * - ensures only one container per file across all threads
+     * The key is the concatenation of the file name and the XPath string
      */
-    private static final Map fileContainers = new HashMap();
+    //@GuardedBy("fileContainers")
+    private static final Map/*<String, XPathFileContainer>*/ fileContainers =
+        new HashMap/*<String, XPathFileContainer>*/();
 
     /* The cache of file packs - for faster local access */
     private static final ThreadLocal filePacks = new ThreadLocal() {
@@ -102,11 +105,15 @@
             }
             // TODO improve the error handling
             if (xpfc == null) {
-                log.error("XPathWrapper is null!");
+                log.error("XPathFileContainer is null!");
                 return ""; //$NON-NLS-1$
             }
             my.put(key,xpfc); // save our local copy
         }
+        if (xpfc.size()==0){
+            log.warn("XPathFileContainer has no nodes: "+file+" "+xpathString);
+            return ""; //$NON-NLS-1$
+        }
         int currentRow = xpfc.nextRow();
         log.debug("getting match number " + currentRow);
         return xpfc.getXPathString(currentRow);
@@ -118,6 +125,8 @@
         my.clear();
         String tname = Thread.currentThread().getName();
         log.info(tname+": clearing container");
-        fileContainers.clear();
+        synchronized (fileContainers) {
+            fileContainers.clear();
+        }
     }
 }

Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=768445&r1=768444&r2=768445&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Sat Apr 25 00:43:18 2009
@@ -203,6 +203,7 @@
 <li>Bug 46993 - Saving from Header Manager generates ClassCastException</li>
 <li>Bug 47009 - Insert parent caused child controller name to be reset</li>
 <li>Bug 47064 - fixes for Mac LAF</li>
+<li>Avoid NPE if XPath function does not match any nodes</li>
 </ul>
 
 <h3>Improvements</h3>

Modified: jakarta/jmeter/trunk/xdocs/usermanual/functions.xml
URL: 
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/functions.xml?rev=768445&r1=768444&r2=768445&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/functions.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/functions.xml Sat Apr 25 00:43:18 2009
@@ -803,7 +803,9 @@
        The XPath function reads an XML file and matches the XPath.
        Each time the function is called, the next match will be returned.
        At end of file, it will wrap around to the start.
-       <note>Note that the entire file is held in memory, so this function 
should not be used for very large files.</note>
+       If no nodes matched, then the function will return the empty string,
+       and a warning message will be written to the JMeter log file.
+       <note>Note that the entire NodeList is held in memory.</note>
        </p>
        <p/>
        Example:



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org

Reply via email to