Bug 63064

Summary: If Controller evaluates to "False" if expression contains empty line
Product: JMeter - Now in Github Reporter: Dirk Ronsmans <ronsmansdirk>
Component: HTTPAssignee: JMeter issues mailing list <issues>
Status: RESOLVED FIXED    
Severity: normal CC: p.mouawad
Priority: P2 Keywords: FixedInTrunk
Version: 5.0   
Target Milestone: JMETER_5.1   
Hardware: PC   
OS: All   
Attachments: trim expression before evaluation

Description Dirk Ronsmans 2019-01-07 13:56:05 UTC
When creating an expression in an If Controller the expression is being evaluated to false when the last line is an empty one.

Tested with "Interpret condition as variable expression" checked.

e.g.
1. ${__jexl3(${blnChangeRadius} == 1)}

Evaluates to true if blnChangeRadius == 1

1. ${__jexl3(${blnChangeRadius} == 1)}
2. 

Evaluates to false when blnChangeRadius == 1

blnChangeRadius in my case was just a random generated number (min:0 max:1)
Comment 1 Felix Schumacher 2019-01-07 19:54:15 UTC
Created attachment 36368 [details]
trim expression before evaluation

The attached patch fixes the reported behavior. The evaluated expression was "true\n" which got compared to "true" which resulted in false.

I haven't committed the patch yet, as I wanted to add a test case so that we would not stumble upon this bug again, but it seems that the expression (condition) is not evaluated at all with my setup. Is anyone willing to tell me, what is missing there?
Comment 2 Philippe Mouawad 2019-01-07 21:04:52 UTC
(In reply to Felix Schumacher from comment #1)
> Created attachment 36368 [details]
> trim expression before evaluation
> 
> The attached patch fixes the reported behavior. The evaluated expression was
> "true\n" which got compared to "true" which resulted in false.
> 
> I haven't committed the patch yet, as I wanted to add a test case so that we
> would not stumble upon this bug again, but it seems that the expression
> (condition) is not evaluated at all with my setup. Is anyone willing to tell
> me, what is missing there?

You need to call ValueReplacer :
        JMeterContextService.getContext().setVariables(vars);
        JMeterContextService.getContext().setSamplingStarted(true);
        ValueReplacer replacer = new ValueReplacer();
        replacer.setUserDefinedVariables(testPlan.getUserDefinedVariables());


Still it doesn't work with function and variable.
Something to be investigated I guess.
Comment 3 Felix Schumacher 2019-01-08 17:33:52 UTC
Thanks for the report. This will be fixed in version 5.1. It would be nice, if you could test the next nightly and report, if it works for you.

@pmouawad I implemented a simpler version of the test, that didn't need any variable expansion at all.

Date: Tue Jan  8 17:30:48 2019
New Revision: 1850776

URL: http://svn.apache.org/viewvc?rev=1850776&view=rev
Log:
Ignore spaces at the end and beginning of expressions used in IfController

Bugzilla Id: 63064

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/control/IfController.java
    jmeter/trunk/test/src/org/apache/jmeter/control/TestIfController.java
    jmeter/trunk/xdocs/changes.xml
Comment 4 The ASF infrastructure team 2022-09-24 20:38:15 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/4972