JavaAdapter masks inherited methods if they implement an interface

RESOLVED FIXED in 1.5R3

Status

Rhino
Core
P3
normal
RESOLVED FIXED
18 years ago
15 years ago

People

(Reporter: Matthias Radestock, Assigned: Norris Boyd)

Tracking

Details

Attachments

(2 attachments)

(Reporter)

Description

18 years ago
Take the following class and interface

public class B {
    public String m2() { return "m2"; }
    public String m4() { return "m4"; }
}

public interface C {
    public String m2();
    public String m3();
}

Now try to execute the following js code:

function F() {}
F.prototype.m3 = function() { return "m3"; }

var f = new JavaAdapter(Packages.B, new F());
f.m2(); //succeeds
var f = new JavaAdapter(Packages.B,Packages.C, new F());
f.m2(); //fails


The problem is that JavaAdapter will generate override-methods for all methods 
defined on any interface *regardless* of whether they are actually defined by 
the JS object. The override masks the implementation of m2 in B.
(Reporter)

Comment 1

18 years ago
Created attachment 19734 [details] [diff] [review]
this patch fixes the problem
(Assignee)

Comment 2

18 years ago
accepted patch--thanks
Status: NEW → RESOLVED
Last Resolved: 18 years ago
Resolution: --- → FIXED
(Assignee)

Comment 3

18 years ago
Kurt Westerfeld discovered that this change causes a regression in some 
JavaAdapter behavior he was depending on:

Subject: 
        Rhino's Interpreted Mode vs. Compiled Mode and Dynamic Scopes
   Date: 
        Mon, 1 Jan 2001 17:10:58 -0500
   From: 
        "Kurt Westerfeld" <kurt@managedobjects.com>
     To: 
        "Norris Boyd" <nboyd@atg.com>




I am having very reproducible problems with using dynamic scopes and rhino when 
dealing with code that is
generated via the Java Adapter (for swing/awt event handlers).  Event handlers I 
am creating using JavaAdapter
are failing to find globally scoped variables whenever run in compiled form and 
dynamic scopes are on. 
However, the same code works fine in interpreted mode.
 
I was going to try to make a little example here, but first I'd like to give you 
an example that used to work with
Rhino but now doesn't:

     this.foo = 'bar'

     var d = new java.awt.Dialog( new java.awt.Frame(), 'Tester', true )
     d.addWindowListener
     (
        new java.awt.event.WindowListener()
        {
           windowClosing: function( evt )
           {
              // Fails?
              java.lang.System.out.println( 'Value of foo: ' + foo )
              d.setVisible( false )
           }
        }
     )
     d.setVisible( true )

This was an attempt to show you the dynamic scope problem, but the JavaAdapter 
actually fails to implement
the java.awt.event.WindowListener interface properly (it doesn't produce all the 
interface members any more).
 
So, here's a fixed version, to show you the dynamic scope problem:

     this.foo = 'bar'

     var d = new java.awt.Dialog( new java.awt.Frame(), 'Tester', true )
     d.addWindowListener
     (
        new java.awt.event.WindowListener()
        {
           windowClosing: function( evt )
           {
              // Fails?
              java.lang.System.out.println( 'Value of foo: ' +  foo )
              d.setVisible( false )
           },
           windowOpened: function( evt ) {},        // Note: all interface 
members now required?
           windowClosed: function( evt ) {},
           windowActivated: function( evt ) {},
           windowDeactivated: function( evt ) {},
           windowIconified: function( evt ) {},
           windowDeiconified: function( evt ) {},
        }
     )
     d.setVisible( true )

So, "foo" can't be found if the scope of the environment is setup in conjunction 
with dynamic scopes.  I'm not
sure why, but there it is.
 
I believe I turned on dynamic scopes because I am populating a shared global 
scope chain, with an importer
top-level, and then another scope whose parent is the importer top-level where 
our statically-defined
"embedding extensions" are defined.  Finally, the read-write "global" scope  is 
created and it's parent is set to
the embedding scope.
 
But, I don't think I need dynamic scopes now because all the embedding does is 
populate with Scriptable (all
Java native) objects.  This subject is still a little confusing to me, and I 
don't think things are working 100% in
my implementation.
 
Any help you can provide would be great.
 
________________________________________________________________________
  Kurt Westerfeld
  Senior Software Architect
  Managed Objects
  mailto:kwester@ManagedObjects.com
  703.770.7225
  http://www.ManagedObjects.com
 
  Managed Objects: manage technology > rule business




Status: RESOLVED → REOPENED
Resolution: FIXED → ---
(Assignee)

Comment 4

18 years ago
Created attachment 21563 [details] [diff] [review]
proposed patch

Comment 5

15 years ago
Marking as fixed as the patch was committed long time ago.
Status: REOPENED → RESOLVED
Last Resolved: 18 years ago15 years ago
Resolution: --- → FIXED

Comment 6

15 years ago
Trageting as resolved against 1.5R5
Target Milestone: --- → 1.5R5

Comment 7

15 years ago
Fixing wrong milestone assignment
Target Milestone: 1.5R5 → 1.5R3
You need to log in before you can comment on or make changes to this bug.