You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2020/07/14 15:31:45 UTC

[plc4x] 01/02: PLC4X-215 - Drivers using the BaseOptimizer (SingleFieldOptimizer) don't handle error responses gracefully - Fixed the issue by only accessing the PlcValue if the return code is 'OK'

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 3ed3bdb674a7d0ffe71e554d031f31658ee812f3
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Tue Jul 14 17:22:50 2020 +0200

    PLC4X-215 - Drivers using the BaseOptimizer (SingleFieldOptimizer) don't handle error responses gracefully
    - Fixed the issue by only accessing the PlcValue if the return code is 'OK'
---
 .../java/org/apache/plc4x/java/spi/optimizer/BaseOptimizer.java    | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/optimizer/BaseOptimizer.java b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/optimizer/BaseOptimizer.java
index c031710..0933ec5 100644
--- a/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/optimizer/BaseOptimizer.java
+++ b/plc4j/spi/src/main/java/org/apache/plc4x/java/spi/optimizer/BaseOptimizer.java
@@ -49,9 +49,10 @@ public abstract class BaseOptimizer {
             for (String fieldName : curRequest.getFieldNames()) {
                 if (readResponse.isLeft()) {
                     PlcReadResponse subReadResponse = (PlcReadResponse) readResponse.getLeft();
-                    fields.put(fieldName,
-                        new ResponseItem<>(subReadResponse.getResponseCode(fieldName),
-                            subReadResponse.getAsPlcValue().getValue(fieldName)));
+                    PlcResponseCode responseCode = subReadResponse.getResponseCode(fieldName);
+                    PlcValue value = (responseCode == PlcResponseCode.OK) ?
+                        subReadResponse.getAsPlcValue().getValue(fieldName) : null;
+                    fields.put(fieldName, new ResponseItem<>(responseCode, value));
                 } else {
                     fields.put(fieldName, new ResponseItem<>(PlcResponseCode.INTERNAL_ERROR, null));
                 }