-
I'm upgrading from Rhino 1.7R4 to 1.7.14, and I think I've stumbled across a change in behavior. I use this method: Scriptable.put(String name, Scriptable start, Object value) And supply a value whose type is StringBuilder. This causes a ClassCastException issue later, in ConsString.flatten(), when it tries to cast the StringBuilder to a String: final String str = (String) next; To temporarily fix this, I've added this block of code:
Was I using Rhino incorrectly before, passing a value whose type is StringBuilder, and just getting lucky? Or could this be an actual regression in Rhino? Any idea if my temporary solution will cause problems in other parts of the engine? Thanks very much for any assistance! |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 14 replies
-
Think you're running into the same as #496 |
Beta Was this translation helpful? Give feedback.
-
If you want to use a StringBuilder as a StringBuilder, that should be possible if you wrap it in a NativeJavaObject. I know you can create StringBuilder instances from within javascript and they work correctly. I haven't fully traced it out, but I assume as soon as you try to concatenate the wrapped StringBuilder with a javascript string, it will coerce the StringBuilder to a String before adding it to the ConsString, so that may not gain you much over calling .toString() in the first place. |
Beta Was this translation helpful? Give feedback.
-
Thanks everyone for your input. Here is a simple program that reproduces the issue we are seeing:
Running this test generates this exception and stack trace:
The ClassCastException happens on the 1st line of this code block in ConsString.flatten():
To temporarily work around the issue, I added this code block immediately before the code block above:
Any chance this is a regression? Does my fix look correct? Thanks again for any input and assistance! |
Beta Was this translation helpful? Give feedback.
-
I'm gonna reopen #496 with a pointer to this discussion. @shelches if you fancy creating a PR for this, that would be great |
Beta Was this translation helpful? Give feedback.
-
I tried the solution suggested by @tonygermano (thanks, Tony!) by changing this:
To this:
Are there any objections to this solution, which changes a single line of code? If not, I can put together a PR. Thanks to everyone for your assistance! |
Beta Was this translation helpful? Give feedback.
-
I spent some time today setting up GitHub (keys, PAT, etc.) but it does not appear I can push to a (non-master/main) branch on the Mozilla Rhino project (a prerequisite to creating a pull request?). I've never used GitHub before, so I'm not sure if I'm simply not allowed access, or if I've done something wrong. Can anyone point me in the right direction? Any assistance is appreciated! |
Beta Was this translation helpful? Give feedback.
-
Also noticed that |
Beta Was this translation helpful? Give feedback.
-
This got resolved via #1210 |
Beta Was this translation helpful? Give feedback.
This got resolved via #1210