karatelabs / karatelabs/karate
2.1.2: Explicitly constructed java.lang.String loses hashCode and equalsIgnoreCase
- Dominant language
- Java
- Stars
- 9k
- Forks
- 2k
- Avg merge
- 8d 15h
- Merged PRs (30d)
- 15
Description
### Description
Methods on an explicitly constructed `java.lang.String` are unavailable in 2.1.2. The unchanged feature passes on 1.5.2. This concerns `Java.type` and `new`, rather than assuming that a native JavaScript string should expose Java-only methods.
The [2.1.2 migration guide](https://github.com/karatelabs/karate/blob/v2.1.2/docs/MIGRATION_GUIDE.md#java-interop) says existing Java interop patterns work unchanged. If this conversion is intentional, please clarify the supported way to retain Java String methods and document the migration.
### Steps to Reproduce
Place the official standalone JAR in an empty directory and save this as `repro.feature`:
```gherkin
Feature: Methods on explicitly constructed Java strings
Scenario: Java String hashCode remains callable
* def JavaString = Java.type('java.lang.String')
* def value = new JavaString('abc')
* match value.hashCode() == 96354
Scenario: Java String equalsIgnoreCase remains callable
* def JavaString = Java.type('java.lang.String')
* def value = new JavaString('ABC')
* match value.equalsIgnoreCase('abc') == true
```
Run `java -jar karate-2.1.2.jar run repro.feature`.
Compare with `java -jar karate-1.5.2.jar repro.feature`.
No browser, server, credentials or configuration file is required.
### Expected Behavior
`hashCode()` returns `96354`, and `equalsIgnoreCase('abc')` returns `true`.
### Actual Behavior
2.1.2 fails both scenarios:
```text
TypeError: value.hashCode is not a function
TypeError: value.equalsIgnoreCase is not a function
```
1.5.2 passes both scenarios using the same Java installation.
### Karate Version
2.1.2 standalone; comparison 1.5.2.
### Java Version
Oracle Java 24.0.2.
### Operating System
macOS ARM64.
Contributor guide
Assessment
This issue has not been assessed yet.