You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jmeter.apache.org by "bugla (via GitHub)" <gi...@apache.org> on 2023/05/08 08:38:20 UTC

[GitHub] [jmeter] bugla commented on issue #3411: Assigning null to a BeanShell variable in a JSR223 sampler does not work as expected

bugla commented on issue #3411:
URL: https://github.com/apache/jmeter/issues/3411#issuecomment-1537975574

   Just ran into that same issue in the current JMeter 5.5.
   
   It is definitely a bug in the included BeanShell library bsh-2.0b6.jar.
   Fortunately it is already fixed in the current BeanShell library bsh-2.1.1.jar. I successfully tested this by locally replacing the library in JMeter and rerunnning the reproduction tests (see below).
   
   As this old bug ticket got a bit convoluted in the comments, I added a concise problem description and easy reproducible example below.
   
   A little clear statement first (as some IMHO strange ideas have been thrown around earlier in the ticket):
   If you add a JSR223 sampler and select "language" as "java (<engine_names_and_versions>)", you expect (and can expect) that it interprets the text written in the section "Script" below as being written in Java.
   That's the whole purpose of that language entry and that kind of handling Scripts is the whole purpose of JSR223 (see: JSR223 Spec: https://jcp.org/aboutJava/communityprocess/final/jsr223/index.html) and JMeter's JSR223 sampler (it's named that way for a reason).
   So yes: It's a bug and there's no doubt about it, it's in an external library, and it's already fixed there.
   
   **Issue**:
   The Java implementation behind "java (BeanShell 2.0b6 / BeanShell Engine 1.0)" is catastrophically wrong concerning the handling of "null" and "void" (with void being new in Java 11 bsh mixed something up, about its usage).
   
   Simplest reproduction (a comparison between openjdk 11 and bsh-2.0b6 in JMeter) (with the same openjdk 11 in the background):
   
   **Code and result from Java**:
   public class VoidTest {
       public static void main(String[] args) {
           System.out.println("Java TEST java.version: " + System.getProperty("java.version")); // 11
           String varX3 = null;
           System.out.println("Java TEST varX3: " + varX3); // null (as it should be)
           System.out.println("Java TEST varX3 is null: " + (varX3 == null)); // true (as it should be)
           // System.out.println("Java TEST varX3 is void: " + (varX3 == void)); // compile fail: illegal start of expression (as it should be)
       }
   }
   
   (Put it in a file "VoidTest.java", run "javac VoidTest.java", run "java VoidTest".)
   --> That result is fully compliant with the Java Language Specification, i.e. by definition openjdk11's implementation of that snippet is correct.
   
   **Code and result from "java (BeanShell 2.0b6 / BeanShell Engine 1.0)"** in JMeter 5.5:
     log.warn("BeanShell TEST java.version: " + System.getProperty("java.version")); // 11
     String varX2 = null;
     log.warn("BeanShell TEST varX2: " + varX2); // void (WRONG!)
     log.warn("BeanShell TEST varX2 is null: " + (varX2 == null)); // false (WRONG!)
     log.warn("BeanShell TEST varX2 is void: " + (varX2 == void)); // true (WRONG!)
   
   --> That result fails to comply with the Java Language Specification, i.e. bsh-2.0b6 is wrong. And that bug is very prolematic as it breaks a lot of correct Java code.
   
   **Fix**:
   Fortunately this has already been fixed in the current version of the BeanShell library bsh-2.1.1.jar (see https://github.com/beanshell/beanshell/releases/tag/2.1.1), which I tested (same test as above, but with lib/bsh-2.0b6.jar replaced with lib/bsh-2.1.1.jar in JMeter5.5 gives the correct result, so no JMeter code needs to be changed, just an external library updated.
   
   While trying to get a PR together, I found that unfortunately bsh-2.1.1.jar is not already published to Maven Central (https://mvnrepository.com/artifact/org.apache-extras.beanshell/bsh), so integrating it in JMeter without that would need some more effort as JMeter seems to only use dependencies from mvnrepository so far.
   
   I did open a ticket in the bsh repository for publishing it in mvnrepository (https://github.com/beanshell/beanshell/issues/739). Probably give this a thumbs-up, if you can, just in case it speeds up things.
   
   Options:
   - We wait for beanshell to publish bsh-2.1.1.jar on Maven Central (mvnrepository.com) and someone does a simple library replacement PR (I would have done it, but see above).
   - A JMeter developer adds a way to retrieve the library directly from https://github.com/beanshell/beanshell .
   
   **Workaround**:
   Replace lib/bsh-2.0b6.jar with lib/bsh-2.1.1.jar in your installation of JMeter5.5.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@jmeter.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org