You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@jmeter.apache.org by bu...@apache.org on 2019/06/20 15:12:48 UTC

[Bug 63522] New: Commented groovy code executed in JSR223 Sampler

https://bz.apache.org/bugzilla/show_bug.cgi?id=63522

            Bug ID: 63522
           Summary: Commented groovy code executed in JSR223 Sampler
           Product: JMeter
           Version: 5.1
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Main
          Assignee: issues@jmeter.apache.org
          Reporter: alex.martian@ya.ru
  Target Milestone: JMETER_5.2

Created attachment 36636
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=36636&action=edit
test plan with commented code being executed

Code ${__intSum(5,i_counter)} is being executed during run on JMeter 5.1 even
as the code is properly commented Java style with //. It's evident by log
output of i_counter variable - see attached test plan. Commenting with /* */
also produces the bug.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 63522] Commented groovy code executed in JSR223 Sampler

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63522

--- Comment #3 from Alex <al...@ya.ru> ---
Thank you for explaining details how JMeter proceeds with JSR223. Will take
care of using such code in the future.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 63522] Commented groovy code executed in JSR223 Sampler

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63522

Philippe Mouawad <p....@ubik-ingenierie.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|JMETER_5.2                  |---

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 63522] Commented groovy code executed in JSR223 Sampler

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63522

Vladimir Sitnikov <si...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

--- Comment #1 from Vladimir Sitnikov <si...@gmail.com> ---
Are you sure it is a bug?
I would say it is a feature :)

Technically speaking, JMeter does not make ${__intSum(5,i_counter)} a new
language feature of JSR223 languages.
In other words, ${__intSum(5,i_counter)}  might easily be an invalid Groovy (or
JavaScript or whatever) code.

In other words, the execution sequence is:
1) JMeter takes "code to execute" as a string
2) It evaluates all ${...} macros there and replaces them with appropriate
values
3) The resulting string is passed to a JSR223 language for interpretation

Note: at step #2 JMeter has absolutely no idea on what syntax is used in
JSR223. In other words, only Groovy engine can tell if the particular line is a
comment, or it is just a part of a multi-line string.

Note 2: it is recommended to AVOID use of ${...} in JSR223 scripts as those
force JMeter to re-evaluate the script code, and the underlying JSR223 engine
has to reparse the code again.


I think it might make sense to just forbid use of JMeter's ${...} macros in
JSR223 code blobs (e.g. disable it by default and allow to temporary override
that).

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 63522] Commented groovy code executed in JSR223 Sampler

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63522

--- Comment #2 from Alex <al...@ya.ru> ---
Comment on attachment 36636
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=36636
test plan with commented code being executed

<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.1 r1853635">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan"
enabled="true">
      <stringProp name="TestPlan.comments"></stringProp>
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables"
elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments"
testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
    </TestPlan>
    <hashTree>
      <SetupThreadGroup guiclass="SetupThreadGroupGui"
testclass="SetupThreadGroup" testname="setUp Thread Group" enabled="true">
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
        <elementProp name="ThreadGroup.main_controller"
elementType="LoopController" guiclass="LoopControlPanel"
testclass="LoopController" testname="Loop Controller" enabled="true">
          <boolProp name="LoopController.continue_forever">false</boolProp>
          <stringProp name="LoopController.loops">1</stringProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
        <longProp name="ThreadGroup.start_time">1560954637000</longProp>
        <longProp name="ThreadGroup.end_time">1560954637000</longProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
      </SetupThreadGroup>
      <hashTree>
        <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler"
testname="JSR223 Sampler - does not execs comments" enabled="true">
          <stringProp name="scriptLanguage">groovy</stringProp>
          <stringProp name="parameters"></stringProp>
          <stringProp name="filename"></stringProp>
          <stringProp name="cacheKey">false</stringProp>
          <stringProp name="script">vars.put
(&quot;i_counter&quot;,&quot;1&quot;);
log.info(vars.get(&apos;i_counter&apos;));
//log.error(Integer.toString(${__intSum(5,i_counter)}));
log.info(vars.get(&quot;i_counter&quot;));
</stringProp>
        </JSR223Sampler>
        <hashTree/>
        <WhileController guiclass="WhileControllerGui"
testclass="WhileController" testname="While Controller" enabled="true">
          <stringProp name="WhileController.condition">&quot;1&quot; ==
&quot;1&quot;</stringProp>
        </WhileController>
        <hashTree>
          <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler"
testname="JSR223 Sampler - execs comments" enabled="true">
            <stringProp name="scriptLanguage">groovy</stringProp>
            <stringProp name="parameters"></stringProp>
            <stringProp name="filename"></stringProp>
            <stringProp name="cacheKey">false</stringProp>
            <stringProp
name="script">//log.error(Integer.toString(${__intSum(5,i_counter)}));
log.info(vars.get(&quot;i_counter&quot;));

</stringProp>
          </JSR223Sampler>
          <hashTree/>
          <ConstantTimer guiclass="ConstantTimerGui" testclass="ConstantTimer"
testname="Constant Timer" enabled="true">
            <stringProp name="ConstantTimer.delay">300</stringProp>
          </ConstantTimer>
          <hashTree/>
        </hashTree>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 63522] Commented groovy code executed in JSR223 Sampler

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63522

--- Comment #4 from Alex <al...@ya.ru> ---
(In reply to Vladimir Sitnikov from comment #1)
> Are you sure it is a bug?
> I would say it is a feature :)
> 
> Technically speaking, JMeter does not make ${__intSum(5,i_counter)} a new
> language feature of JSR223 languages.
> In other words, ${__intSum(5,i_counter)}  might easily be an invalid Groovy
> (or JavaScript or whatever) code.
> 
> In other words, the execution sequence is:
> 1) JMeter takes "code to execute" as a string
> 2) It evaluates all ${...} macros there and replaces them with appropriate
> values
> 3) The resulting string is passed to a JSR223 language for interpretation
> 
> Note: at step #2 JMeter has absolutely no idea on what syntax is used in
> JSR223. In other words, only Groovy engine can tell if the particular line
> is a comment, or it is just a part of a multi-line string.
> 
> Note 2: it is recommended to AVOID use of ${...} in JSR223 scripts as those
> force JMeter to re-evaluate the script code, and the underlying JSR223
> engine has to reparse the code again.
> 
> 
> I think it might make sense to just forbid use of JMeter's ${...} macros in
> JSR223 code blobs (e.g. disable it by default and allow to temporary
> override that).

Vladimir, yesterday I just wrote to you as a comment, now I do [reply], I still
see my post in NEW status, so I guess I needed to [reply] to you. Should I mark
it as resolved or you prefer in NEW for work you wrote at the end?

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 63522] Commented groovy code executed in JSR223 Sampler

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=63522

Philippe Mouawad <p....@ubik-ingenierie.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |WORKSFORME
                 CC|                            |p.mouawad@ubik-ingenierie.c
                   |                            |om

-- 
You are receiving this mail because:
You are the assignee for the bug.