diff --git a/src/main/java/com/ibm/watson/modelmesh/ModelMesh.java b/src/main/java/com/ibm/watson/modelmesh/ModelMesh.java index 54a9ebe4d..7422a0870 100644 --- a/src/main/java/com/ibm/watson/modelmesh/ModelMesh.java +++ b/src/main/java/com/ibm/watson/modelmesh/ModelMesh.java @@ -4430,7 +4430,16 @@ private Object invokeLocalModel(CacheEntry ce, Method method, Object[] args) ce.upgradePriority(now + 3600_000L, now + 7200_000L); // (2 hours in future) } Map contextMap = ThreadContext.getCurrentContext(); - String vModelId = contextMap.getOrDefault(VMODELID, ""); + String vModelId = null; + // We might arrive here from a path where the original call was with a modelid. + // Hence, it is possible to arrive here with a null contextMap because the vModelId was never set + // To avoid catching a null pointer exception we just sanity check instead. + if (contextMap == null) { + vModelId = ""; + } else { + vModelId = contextMap.get(VMODELID); + } + // The future-waiting timeouts should not be needed, request threads are interrupted when their // timeouts/deadlines expire, and the model loading thread that it waits for has its own timeout. // But we still set a large one as a safeguard (there can be pathalogical cases where model-loading