Duplicate :
|
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)