jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1840365 - in /jmeter/trunk: src/functions/org/apache/jmeter/functions/IsVarDefined.java test/src/org/apache/jmeter/functions/TestIsVarDefined.java
Date Sat, 08 Sep 2018 15:16:12 GMT
Author: pmouawad
Date: Sat Sep  8 15:16:12 2018
New Revision: 1840365

URL: http://svn.apache.org/viewvc?rev=1840365&view=rev
Log:
Avoid NPE when called from Function Helper Dialog

Modified:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/IsVarDefined.java
    jmeter/trunk/test/src/org/apache/jmeter/functions/TestIsVarDefined.java

Modified: jmeter/trunk/src/functions/org/apache/jmeter/functions/IsVarDefined.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/IsVarDefined.java?rev=1840365&r1=1840364&r2=1840365&view=diff
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/IsVarDefined.java (original)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/IsVarDefined.java Sat Sep  8 15:16:12
2018
@@ -25,6 +25,7 @@ import java.util.List;
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.threads.JMeterVariables;
 import org.apache.jmeter.util.JMeterUtils;
 
 /**
@@ -50,8 +51,13 @@ public class IsVarDefined extends Abstra
     public String execute(SampleResult previousResult, Sampler currentSampler)
             throws InvalidVariableException {
         String variableName = values[0].execute();
-        String variableValue = getVariables().get(variableName);
-        return Boolean.toString(variableValue != null);
+        JMeterVariables jMeterVariables = getVariables();
+        if(jMeterVariables != null) {
+            String variableValue = jMeterVariables.get(variableName);
+            return Boolean.toString(variableValue != null);
+        } else {
+            return Boolean.FALSE.toString();
+        }
     }
 
     @Override

Modified: jmeter/trunk/test/src/org/apache/jmeter/functions/TestIsVarDefined.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/functions/TestIsVarDefined.java?rev=1840365&r1=1840364&r2=1840365&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/functions/TestIsVarDefined.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/functions/TestIsVarDefined.java Sat Sep  8 15:16:12
2018
@@ -98,5 +98,14 @@ public class TestIsVarDefined extends JM
         isVarDefined.setParameters(params);
         isVarDefined.execute(result, null);
     }
+    
+    @Test
+    public void testNoVariablesDefined() throws Exception {
+        jmctx.setVariables(null);
+        params.add(new CompoundVariable("emptyProperty"));
+        isVarDefined.setParameters(params);
+        String returnValue = isVarDefined.execute(result, null);
+        assertEquals("false", returnValue);
+    }
 
 }



Mime
View raw message