2.1.2: Java String constructor fails when its byte-array argument is a method call
Description
A nested method call inside a Java String constructor fails on 2.1.2. Assigning the identical byte array to a variable before constructing the string succeeds. Both forms work on 1.5.2. This reproduces without a browser, application, credentials or configuration file.
Steps to Reproduce
Place the official standalone JAR in an empty directory and save this as repro.feature:
Feature: Java constructor argument evaluation
Scenario: Construct directly from decoded bytes
* def Base64 = Java.type('java.util.Base64')
* def result = new java.lang.String(Base64.getDecoder().decode('c2FtcGxl'), 'UTF-8')
* match result == 'sample'Run java -jar karate-2.1.2.jar run repro.feature.
Compare the unchanged feature with java -jar karate-1.5.2.jar repro.feature.
Expected Behavior
The constructor receives the decoded byte array, returns sample, and the test passes.
Actual Behavior
2.1.2 fails with TypeError: String is not a constructor. 1.5.2 passes.
The same failure occurs with a named class alias:
* def JString = Java.type('java.lang.String')
* def result = new JString(Base64.getDecoder().decode('c2FtcGxl'), 'UTF-8')This control passes on both versions:
* def bytes = Base64.getDecoder().decode('c2FtcGxl')
* def result = new java.lang.String(bytes, 'UTF-8')
* match result == 'sample'Full three-scenario control: 2.1.2 passes 1/3; 1.5.2 passes 3/3.
Karate Version
2.1.2 standalone; comparison 1.5.2.
Java Version
Oracle Java 24.0.2.
Operating System
macOS ARM64.
Source: karatelabs/karate