There is a bug in the method eq(Object x, Object y) of ScriptRuntime class.

RESOLVED INVALID

Status

Rhino
Core
--
critical
RESOLVED INVALID
11 years ago
11 years ago

People

(Reporter: xiaofeng.zhang, Unassigned)

Tracking

Details

(Reporter)

Description

11 years ago
User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
Build Identifier: 

My case is:
x is an instance of a class which implements the Scriptable and Wrapper.  (Wrapper)x).unwrap() equal null. y is also null.
The right return value is true. But the method will return false;

Reproducible: Always

Comment 1

11 years ago
What's your suggestion? Should we maybe add

if(x instanceof Wrapper) x = ((Wrapper)x).unwrap();
if(y instanceof Wrapper) y = ((Wrapper)y).unwrap();

as first two lines of eq()?

Comment 2

11 years ago
Actually, I don't think you're right. A wrapper object that wraps a null is just *not* equivalent to null in itself. OTOH, two wrappers that both wrap a null are equal. This is how the current implementation works, and I think it is correct.

Any automatic coercion mechanism always leaves room for multiple interpretations, so there could probably be a use case where it'd be desirable if semantics of eq would support wrapper(null) == null, but it is not the case generally. Regardless of the fact that Rhino is *quite* transparent when it comes to exposing Java objects as JS objects, there are some impedance mismatches - such as this. I'd strongly suggest that when you need to wrap a Java null, you just leave it as a null instead of creating a wrapper.
Status: NEW → RESOLVED
Last Resolved: 11 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.