JDK-8062624 : java.lang.String methods not available on concatenated strings
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u40,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-10-31
  • Updated: 2015-06-04
  • Resolved: 2014-11-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u40Fixed 9 b39Fixed
Related Reports
Duplicate :  
Description
Code for reproduce :

print("JS + JS")
print(("" + "").replace)
print(("" + "").replaceAll)

print("Java + JS")
print((new java.lang.String("")+ "").replace)
print((new java.lang.String("") + "").replaceAll)

print("Types are same")
print((new java.lang.String("")+ "").class)
print(("" + "").class)

Output :

JS + JS
function replace() { [native code] }
[jdk.internal.dynalink.beans.SimpleDynamicMethod String java.lang.String.replaceAll(String,String)]

Java + JS
function replace() { [native code] }
undefined

Types are same
class java.lang.String
class java.lang.String

reproducing in jdk 9b37/8u40b12 with/without OT


Comments
The issue is not related to mixing Java and JavaScript strings as the original report suggests. Rather, it is an issue with invoking java.lang.String methods on Nashorn ConsStrings. Concatenating two string literals in Nashorn just happens to statically evaluated to a String which is why the issue does not occur in this case.
05-11-2014