Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid NPE following ASH error #1435

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -869,17 +869,16 @@ public EzspTransaction sendEzspTransaction(EzspTransaction ezspTransaction, long
Future<EzspFrame> futureResponse = sendEzspRequestAsync(ezspTransaction);
if (futureResponse == null) {
logger.debug("ASH: Error sending EZSP transaction: Future is null");
return null;
}

try {
futureResponse.get(timeout, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException e) {
futureResponse.cancel(true);
logger.debug("ASH interrupted in sendRequest while sending {}", ezspTransaction.getRequest());
} catch (TimeoutException e) {
futureResponse.cancel(true);
logger.debug("Sending EZSP transaction timed out after {} seconds", timeout);
} else {
try {
futureResponse.get(timeout, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException e) {
futureResponse.cancel(true);
logger.debug("ASH interrupted in sendRequest while sending {}", ezspTransaction.getRequest());
} catch (TimeoutException e) {
futureResponse.cancel(true);
logger.debug("Sending EZSP transaction timed out after {} seconds", timeout);
}
}

return ezspTransaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public interface EzspTransaction {
* response indicating the final state of the transaction.
*
* @return {@link EmberStatus} indicating the transaction completion state or
* {@link EmberStatus#EMBED_UNKNOWN_STATUS} on error.
* {@link EmberStatus#UNKNOWN} on error.
*/
EmberStatus getStatus();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand All @@ -33,6 +32,7 @@
import com.zsmartsystems.zigbee.dongle.ember.ezsp.EzspFrameRequest;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspVersionRequest;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.command.EzspVersionResponse;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EmberStatus;
import com.zsmartsystems.zigbee.dongle.ember.internal.EzspFrameHandler;
import com.zsmartsystems.zigbee.dongle.ember.internal.transaction.EzspSingleResponseTransaction;
import com.zsmartsystems.zigbee.dongle.ember.internal.transaction.EzspTransaction;
Expand Down Expand Up @@ -170,7 +170,7 @@ public void write(int value) {

@Override
public void write(int[] bytes) {
for(int val : bytes) {
for (int val : bytes) {
outputData.add(val);
}
}
Expand Down Expand Up @@ -318,4 +318,19 @@ public void handleReset() throws Exception {

Mockito.verify(ezspHandler, Mockito.timeout(TIMEOUT)).handleLinkStateChange(true);
}

@Test
public void sendEzspTransactionNullCheck() {
EzspFrameHandler ezspHandler = Mockito.mock(EzspFrameHandler.class);
AshFrameHandler frameHandler = new AshFrameHandler(ezspHandler);

frameHandler.setClosing();
EzspVersionRequest request = new EzspVersionRequest();
EzspTransaction transaction = frameHandler
.sendEzspTransaction(new EzspSingleResponseTransaction(request, EzspVersionResponse.class));

assertNotNull(transaction);
assertEquals(EmberStatus.UNKNOWN, transaction.getStatus());
assertNull(transaction.getResponse());
}
}
Loading