From db88b6f9deac5f21535d2580b8f98f18f4481412 Mon Sep 17 00:00:00 2001 From: FROGbots-4634 Date: Sat, 8 Feb 2020 09:30:31 -0500 Subject: [PATCH] Potentially fix NPE with bulk cache --- .../qualcomm/hardware/lynx/LynxModule.java | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Hardware/src/main/java/com/qualcomm/hardware/lynx/LynxModule.java b/Hardware/src/main/java/com/qualcomm/hardware/lynx/LynxModule.java index f02a92c7..2d1b31ef 100644 --- a/Hardware/src/main/java/com/qualcomm/hardware/lynx/LynxModule.java +++ b/Hardware/src/main/java/com/qualcomm/hardware/lynx/LynxModule.java @@ -1368,24 +1368,26 @@ public double getAnalogInputVoltage(int inputZ, VoltageUnit unit) */ public BulkData getBulkData() { - clearBulkCache(); - - LynxGetBulkInputDataCommand command = new LynxGetBulkInputDataCommand(this); - try - { - LynxGetBulkInputDataResponse response = command.sendReceive(); synchronized (bulkCachingLock) + { + clearBulkCache(); + + LynxGetBulkInputDataCommand command = new LynxGetBulkInputDataCommand(this); + try { - lastBulkData = new BulkData(response); - return lastBulkData; + LynxGetBulkInputDataResponse response = command.sendReceive(); + lastBulkData = new BulkData(response); + return lastBulkData; + } + catch (InterruptedException|RuntimeException|LynxNackException e) + { + handleException(e); } - } - catch (InterruptedException|RuntimeException|LynxNackException e) - { - handleException(e); - } - return LynxUsbUtil.makePlaceholderValue(new BulkData(new LynxGetBulkInputDataResponse(this))); + BulkData placeholder = LynxUsbUtil.makePlaceholderValue(new BulkData(new LynxGetBulkInputDataResponse(this))); + lastBulkData = placeholder; + return placeholder; + } } /**