JDK-4730878 : PortableRemoteObject.narrow(...) should not cast result to java.rmi.Remote
  • Type: Bug
  • Component: other-libs
  • Sub-Component: corba:orb
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.6
  • CPU: generic
  • Submitted: 2002-08-13
  • Updated: 2003-01-07
  • Resolved: 2004-12-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
1.3.1 07Fixed
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).

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.3.1_07 1.4.0_04 1.4.1_02 mantis FIXED IN: 1.3.1_07 1.4.0_04 1.4.1_02 mantis INTEGRATED IN: 1.3.1_07 1.4.0_04 1.4.1_02 mantis mantis-b08

EVALUATION Will fix it for 1.4.2 since it is too late for 1.4.1 and also, it may go in 1.3.1 and 1.4.0 patches.