diff --git a/src/main/java/me/legrange/mikrotik/impl/ApiConnectionImpl.java b/src/main/java/me/legrange/mikrotik/impl/ApiConnectionImpl.java index 801510d..9f26883 100644 --- a/src/main/java/me/legrange/mikrotik/impl/ApiConnectionImpl.java +++ b/src/main/java/me/legrange/mikrotik/impl/ApiConnectionImpl.java @@ -255,20 +255,24 @@ public void run() { } catch (MikrotikApiException ex) { continue; } - ResultListener l = listeners.get(res.getTag()); - if (l != null) { - if (res instanceof Result) { - l.receive((Result) res); - } else if (res instanceof Done) { - if (l instanceof SyncListener) { - ((SyncListener) l).completed((Done) res); - } else { - l.completed(); + if (res.getTag() != null) { + ResultListener l = listeners.get(res.getTag()); + if (l != null) { + if (res instanceof Result) { + l.receive((Result) res); + } else if (res instanceof Done) { + if (l instanceof SyncListener) { + ((SyncListener) l).completed((Done) res); + } else { + l.completed(); + } + listeners.remove(res.getTag()); + } else if (res instanceof Error) { + l.error(new ApiCommandException((Error) res)); } - listeners.remove(res.getTag()); - } else if (res instanceof Error) { - l.error(new ApiCommandException((Error) res)); } + } else { + nextTag(); } } }