If the remote interface isn't accessible (e.g., it's in a package that isn't exported or open to the java.rmi module), the wrong exception is thrown.
The runtime throws InaccessibleObjectException from the call to setAccessible(). This occurs within UnicastServerRef.exportObject() within the call to hashToMethod_Maps.get(). This exception is propagated all the way out to the caller. Worse, this exception is thrown after the object is entered into the object table, so it has an entry for which no stub can be created.
USR.exportObject() should catch this exception and wrap it in a StubNotFoundException. It should also move the hashToMethod_Maps.get() call earlier, to preserve failure atomicity.
The runtime throws InaccessibleObjectException from the call to setAccessible(). This occurs within UnicastServerRef.exportObject() within the call to hashToMethod_Maps.get(). This exception is propagated all the way out to the caller. Worse, this exception is thrown after the object is entered into the object table, so it has an entry for which no stub can be created.
USR.exportObject() should catch this exception and wrap it in a StubNotFoundException. It should also move the hashToMethod_Maps.get() call earlier, to preserve failure atomicity.