From 241b3d4ce2320244e1a0a9c99efc3e128b87f341 Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 9 Jan 2019 23:22:54 +0100 Subject: [PATCH] Fixed RMI so that the impl class does not have to be registered in order to construct a proxy object --- src/dorkbox/network/connection/ConnectionImpl.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/dorkbox/network/connection/ConnectionImpl.java b/src/dorkbox/network/connection/ConnectionImpl.java index 29316633..061540e5 100644 --- a/src/dorkbox/network/connection/ConnectionImpl.java +++ b/src/dorkbox/network/connection/ConnectionImpl.java @@ -1144,9 +1144,22 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements CryptoConne try { kryo = manager.takeKryo(); + + // because the INTERFACE is what is registered with kryo (not the impl) we have to temporarily permit unregistered classes (which have an ID of -1) + // so we can cache the instantiator for this class. + boolean registrationRequired = kryo.isRegistrationRequired(); + + kryo.setRegistrationRequired(false); + // this is what creates a new instance of the impl class, and stores it as an ID. object = kryo.newInstance(implementationClass); + if (registrationRequired) { + // only if it's different should we call this again. + kryo.setRegistrationRequired(true); + } + + rmiId = rmiBridge.register(object); if (rmiId == RmiBridge.INVALID_RMI) {