diff --git a/src/main/java/com/actiontech/dble/services/BackendService.java b/src/main/java/com/actiontech/dble/services/BackendService.java index 0127141fa2..048d33c621 100644 --- a/src/main/java/com/actiontech/dble/services/BackendService.java +++ b/src/main/java/com/actiontech/dble/services/BackendService.java @@ -211,7 +211,7 @@ void parseErrorPacket(byte[] data, String reason) { @Override protected void handleInnerData(byte[] data) { if (connection.isClosed()) { - if (data.length > 4 && data[4] == ErrorPacket.FIELD_COUNT) { + if (data != null && data.length > 4 && data[4] == ErrorPacket.FIELD_COUNT) { parseErrorPacket(data, "connection close"); } return; @@ -241,11 +241,11 @@ protected void handleDataError(Exception e) { } private void clearTaskQueue() { - while (!taskQueue.isEmpty()) { - final ServiceTask task = taskQueue.poll(); + ServiceTask task; + while ((task = taskQueue.poll()) != null) { if (task.getType() == ServiceTaskType.NORMAL) { final byte[] data = ((NormalServiceTask) task).getOrgData(); - if (data.length > 4 && data[4] == ErrorPacket.FIELD_COUNT) { + if (data != null && data.length > 4 && data[4] == ErrorPacket.FIELD_COUNT) { parseErrorPacket(data, "cleanup"); } }