Closed Bug 204513 Opened 22 years ago Closed 22 years ago

Not recognizing JS primitive string as CharSequence

Categories

(Rhino Graveyard :: Core, defect)

x86
Windows XP
defect
Not set
normal

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: timothy.folks, Assigned: norrisboyd)

References

Details

Attachments

(1 file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3) Gecko/20030312 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3) Gecko/20030312 Running under Java 1.4.1 Calling a Java method that takes a CharSequence and passing either a JavaScript string or a Java string results in "Can't find method(string)" or "Cannot convert <string> to java.lang.CharSequence" respectively. Reproducible: Always Steps to Reproduce: 1. Using Java 1.4 or higher, create a simple Java class: public Foo { void bar(CharSequence cs) { //Do something } } 2. Compile the class. 3. Start Rhino with Foo in the classpath. 4. importClass(Packages.Foo); 5. var o = new Foo 6. o.bar('somestring'); Actual Results: Message returned: "<stdin>", line 3: Can't find method Foo.bar(string). Expected Results: Simply returned to the shell prompt without error
cc'ing Igor -
Just clarifying: in the sample Foo class posted with the initial report, void bar should be *public* void bar. It was a typo. The public void bar method generates the error message.
1. Inability to use instances of Java String obtained via LiveConnect as an argument to Java method taking CharSequence parameter. This is a regression since Rhino 1.5R3 and I will file a separated bug for that. For example in 1.5R3 the following prints 4 as expected but in 1.5R4* it gives an exception: var length = Packages.test.length(java.lang.String("test")) print(length) where test is public class test { public static int length(CharSequence cs) { return cs.length(); } } 2. Inability to use JS primitive strings as an argument to Java method taking CharSequence parameter (this bug). It never worked so it is just a new feature to support. Note that the fact that JS primitive strings are represented internally by instances of java.lang.String does not matter here since LiveConnect support treats them in a very different way than instances of java.lang.String exposed to scripts via LiveConnect.
Status: NEW → ASSIGNED
Changing title to better reflect the bug nature
Summary: Not recognizing String as CharSequence → Not recognizing JS primitive as CharSequence
Summary: Not recognizing JS primitive as CharSequence → Not recognizing JS primitive string as CharSequence
Depends on: 204576
The fix replaces explicit checks to see if type is Object, Serializable or Comparable by more generic calls to type.isInstance(str) which covers CharSequence case as well.
I committed the fix
Status: ASSIGNED → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Verified FIXED. Below, I compare Rhino1_5R3 vs. Rhino1_5R5pre before and after the fix. For "//Do something" in Tim's testcase above, I put: System.out.println("\nYOU HAVE FOUND THE Foo.bar METHOD\n"); ------------------------------ Rhino1_5R3: ------------------------------ [ ] java -classpath ".;D:/JS_TRUNK/mozilla/js/rhino/build/rhino1_5R3/js.jar" org.mozilla.javascript.tools.shell.Main Rhino 1.5 release 3 2002 01 24 js> importClass(Packages.Foo); js> var o = new Foo; js> o Foo@540408 ------------------ PROVIDING A JS PRIMITIVE STRING ------------------ js> o.bar('test'); js: "<stdin>", line 4: Can't find method Foo.bar(string). --------------------- PROVIDING A JAVA STRING ---------------------- js>o.bar(java.lang.String("test")) YOU HAVE FOUND THE Foo.bar METHOD -------------------------- Rhino1_5R5pre BEFORE --------------------------- [ ] java -classpath ".;D:/JS_TRUNK/mozilla/js/rhino/build/rhino1_5R5pre/js.jar" org.mozilla.javascript.tools.shell.Main Rhino 1.5 release 5 0000 00 00 js> importClass(Packages.Foo); js> var o = new Foo; js> o Foo@18a7efd ------------------ PROVIDING A JS PRIMITIVE STRING ------------------ js> o.bar('test'); js: "<stdin>", line 4: Can't find method Foo.bar(string). --------------------- PROVIDING A JAVA STRING ---------------------- js> o.bar(java.lang.String("test")) js: "<stdin>", line 6: Can't find method Foo.bar(string). -------------------------- Rhino1_5R5pre AFTER --------------------------- [ ] java -classpath ".;D:/JS_TRUNK/mozilla/js/rhino/build/rhino1_5R5pre/js.jar" org.mozilla.javascript.tools.shell.Main Rhino 1.5 release 5 0000 00 00 js> importClass(Packages.Foo); js> var o = new Foo; js> o Foo@18a7efd ------------------ PROVIDING A JS PRIMITIVE STRING ------------------ js> o.bar('test'); YOU HAVE FOUND THE Foo.bar METHOD --------------------- PROVIDING A JAVA STRING ---------------------- js>o.bar(java.lang.String("test")) YOU HAVE FOUND THE Foo.bar METHOD
Status: RESOLVED → VERIFIED
Targeting as resolved against 1.5R5
Target Milestone: --- → 1.5R5
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: