From f94f15cf8b586ae61dfd3161597a026c773fb703 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 16 Nov 2015 22:20:13 +0100 Subject: [PATCH] Added null checks wrt globalRmiBridge --- .../network/connection/ConnectionImpl.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Dorkbox-Network/src/dorkbox/network/connection/ConnectionImpl.java b/Dorkbox-Network/src/dorkbox/network/connection/ConnectionImpl.java index d4556fe2..849acea3 100644 --- a/Dorkbox-Network/src/dorkbox/network/connection/ConnectionImpl.java +++ b/Dorkbox-Network/src/dorkbox/network/connection/ConnectionImpl.java @@ -806,6 +806,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements Connection, // this means we are creating a NEW object on the server, bound access to only this connection TCP(new RmiRegistration(remoteImplementationClass.getName())).flush(); + //noinspection Duplicates try { if (!objectRegistrationLatch.latch.await(2, TimeUnit.SECONDS)) { final String errorMessage = "Timed out getting registration ID for: " + remoteImplementationClass; @@ -842,6 +843,7 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements Connection, // this means that we are ACCESSING a remote object on the server, the server checks GLOBAL, then LOCAL for this object TCP(new RmiRegistration(objectId)).flush(); + //noinspection Duplicates try { if (!objectRegistrationLatch.latch.await(2, TimeUnit.SECONDS)) { final String errorMessage = "Timed out getting registration for ID: " + objectId; @@ -947,7 +949,13 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements Connection, public int getRegisteredId(final T object) { // always check local before checking global, because less contention on the synchronization - int object1 = endPoint.globalRmiBridge.getRegisteredId(object); + RmiBridge globalRmiBridge = endPoint.globalRmiBridge; + + if (globalRmiBridge == null) { + throw new NullPointerException("Unable to call 'getRegisteredId' when the gloablRmiBridge is null!"); + } + + int object1 = globalRmiBridge.getRegisteredId(object); if (object1 == Integer.MAX_VALUE) { return rmiBridge.getRegisteredId(object); } else { @@ -980,7 +988,13 @@ class ConnectionImpl extends ChannelInboundHandlerAdapter implements Connection, public Object getImplementationObject(final int objectID) { if (RmiBridge.isGlobal(objectID)) { - return endPoint.globalRmiBridge.getRegisteredObject(objectID); + RmiBridge globalRmiBridge = endPoint.globalRmiBridge; + + if (globalRmiBridge == null) { + throw new NullPointerException("Unable to call 'getRegisteredId' when the gloablRmiBridge is null!"); + } + + return globalRmiBridge.getRegisteredObject(objectID); } else { return rmiBridge.getRegisteredObject(objectID); }