Closed Bug 311240 Opened 19 years ago Closed 19 years ago

XPCOMJavaProxy "equals()" method doesn't check actual XPCOM object

Categories

(Core Graveyard :: Java to XPCOM Bridge, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: jhpedemonte, Assigned: jhpedemonte)

Details

(Keywords: fixed1.8.0.1, fixed1.8.1, Whiteboard: javaconnect-to-branch)

Attachments

(1 file, 1 obsolete file)

The |XPCOMJavaProxy.proxyEquals()| handles the |Object.equals()| calls.  But it
only checks if the Java objects are the same;  the method doesn't check if the
underlying XPCOM objects are the same (in the case where the Java objects are
different but representing the same XPCOM object).
Attached patch patch (obsolete) — Splinter Review
Still not completely sure about this patch, but whatever the final fix is, it should be checked in to 1.8 branch.  Adding "javaconnect-to-branch" to whiteboard.
Whiteboard: javaconnect-to-branch
OK, so now I understand better why we need this patch.  The issue presents itself when we have an XPCOM object that implements multiple interfaces.  If passed to Java as InterfaceA, JavaXPCOM creates a Java proxy for that interface.  Later, if that XPCOM object is passed to Java as InterfaceB, JavaXPCOM creates another Java proxy for that interface.

So we have two Java proxies that implement different interfaces but represent the same object.  If we try to compare the two Java proxies for equality, it fails.  This patch overrides the |equals()| method to compare the underlying XPCOM objects.

It would be great if I could add an interface to an existing Java proxy, but that doesn't seem to be possible.

What would be best would be to create a Java proxy with all the interfaces that an XPCOM object implements.  But it seems that the only way to get all the implemented interfaces is if the XPCOM object implements "nsIClassInfo", correct?  Is there another way to get the implemented interfaces of an object?
If an object doesn't implement classinfo, then you're out of luck. And there are cases where classinfo doesn't list all the interfaces implemented by an object, since we overload the meaning of classinfo to support DOM scripting :-(

xpconnect solves this by dynamically adding tearoffs to an object, but if Java can't do that then this patch is the right way to go.
If I understand tearoffs correctly, the it won't work with java.lang.Object's |equals| method.  So I'll just have to stick with this patch to overload |equals| to check the XPCOM objects themselves.
I think I've asked this before, but just to be sure: when comparing two XPCOM objects together, I need to QI them to |nsISupports| first, right?
Yes.
Attached patch patch v2Splinter Review
Turns out I was doing quite a few things wrong.  First, I should be saving the root pointer of the XPCOM object (i.e. QI'd to nsISupports).  Second, in the convenience methods (i.e. |GetComponentManager|), I was creating a new Java proxy each time; in this patch, I make all requests for Java objects go though |GetNewOrUsedJavaObject|, which takes care of searching the hash tables and creating new Java proxies if necessary.
Attachment #198607 - Attachment is obsolete: true
Attachment #207551 - Flags: review?(benjamin)
Comment on attachment 207551 [details] [diff] [review]
patch v2

I don't actually know all the java proxy stuff very well, but this looks good from an XPCOM identity point of view.

a=me for branches as this is javaxpcom-only
Attachment #207551 - Flags: review?(benjamin)
Attachment #207551 - Flags: review+
Attachment #207551 - Flags: approval1.8.1+
Attachment #207551 - Flags: approval1.8.0.1+
Checked in to trunk.
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Fixed on MOZILLA_1_8_BRANCH and MOZILLA_1_8_0_BRANCH.
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: