From 13a8dde8a6afb018ce96bcfb97929c006be97f50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sun, 18 Jan 2015 14:27:23 +0100 Subject: [PATCH] Fixed highly unlikely, non-critical NPE in machine (could happen in the very rare case that an executor thread started while the machine was being removed from the network, leading it to run while the machine is unconnected - that's still possible, but non-critical; it'll just stop/silently error and stop now). --- src/main/scala/li/cil/oc/server/machine/Machine.scala | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/scala/li/cil/oc/server/machine/Machine.scala b/src/main/scala/li/cil/oc/server/machine/Machine.scala index 31fd20ce6..c895aeaee 100644 --- a/src/main/scala/li/cil/oc/server/machine/Machine.scala +++ b/src/main/scala/li/cil/oc/server/machine/Machine.scala @@ -255,7 +255,7 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach }) override def invoke(address: String, method: String, args: Array[AnyRef]) = - Option(node.network.node(address)) match { + if (node != null && node.network != null) Option(node.network.node(address)) match { case Some(component: Component) if component.canBeSeenFrom(node) || component == node => val direct = component.annotation(method).direct if (direct && architecture.isInitialized) { @@ -264,6 +264,11 @@ class Machine(val host: MachineHost) extends prefab.ManagedEnvironment with mach component.invoke(method, this, args: _*) case _ => throw new IllegalArgumentException("no such component") } + else { + // Not really, but makes the VM stop, which is what we want in this case, + // because it means we've been disconnected / disposed already. + throw new LimitReachedException() + } override def invoke(value: Value, method: String, args: Array[AnyRef]): Array[AnyRef] = Callbacks(value).get(method) match { case Some(callback) =>