Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4730878

PortableRemoteObject.narrow(...) should not cast result to java.rmi.Remote

XMLWordPrintable

    • 07
    • generic
    • solaris_2.6
    • Not verified

        com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(...) casts the returned result to the java.rmi.Remote interface.

        This doesn't work in all cases. The incorrect code (see the two lines below) is inside com.sun.corba.se.internal.util.Utility.loadStub(...). The narrow method calls this loadStub method to create a stub.

         // Create a stub instance and set the delegate...
         result = (Remote) resultClass.newInstance();

        This behavior is contradiciting the spec of javax.rmi.PortableRemoteObject.narrow(...): "Checks to ensure that an object of a remote or abstract interface type can be cast to a desired type"

        Since the abstract interfaces do not implement Remote, this code will break for customers using abstract interfaces in their application. This code results in ClassCastException like the following one:

        java.lang.ClassCastException: Bank._Account_Stub
        at com.sun.corba.se.internal.util.Utility.loadStub(Utility.java:754)
        at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:287)
        at javax.rmi.PortableRemoteObject.narrow(Unknown Source)
        at Bank._AccountManager_Stub.create(_AccountManager_Stub.java:109)
        at ClientApplet.action(ClientApplet.java:91)
        at java.awt.Component.handleEvent(Unknown Source)
        at java.awt.Component.postEvent(Unknown Source)
        at java.awt.Component.postEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)


        This code fails for customer Borland. Borland believes that the result should be cast to javax.rmi.CORBA.Stub (spec defined stub base) (loadStub's return type should be modified too).

              kcavanauorcl Ken Cavanaugh (Inactive)
              ksoshals Kirill Soshalskiy (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: