JDK-8063045 : .startsWith() not supported on concatenated strings
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u25
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86_64
  • Submitted: 2014-11-04
  • Updated: 2014-11-05
  • Resolved: 2014-11-05
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux ... 3.11.6-4-desktop #1 SMP PREEMPT Wed Oct 30 18:04:56 UTC 2013 (e6d4a27) x86_64 x86_64 x86_64 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
When concatenating strings in Nashorn, either with + or with .concat(), the resulting string object doesn't have a .startsWith(). Other string objects do support this method.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
nashorn> a = "a";
a
nashorn> a.startsWith("a");
true
nashorn> b = a + a;
aa
nashorn> b.startsWith("a");
script error: TypeError: ab has no such function "startsWith" in <STDIN> at line number 1
nashorn> b = a.concat(a);
aa
nashorn> b.startsWith("a");
script error: TypeError: ab has no such function "startsWith" in <STDIN> at line number 1
nashorn> typeof(a)
string
nashorn> typeof(b)
string
nashorn> a.class
class java.lang.String
nashorn> b.class
class java.lang.String


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect every string object to have the same methods.

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
b = String(b)