Claus Ibsen created CAMEL-26180:
-----------------------------------

             Summary: camel-plc4x - a write tag Map with several addresses 
writes only the first, and the polling consumer throws out of receive() for an 
unknown tag
                 Key: CAMEL-26180
                 URL: https://issues.apache.org/jira/browse/CAMEL-26180
             Project: Camel
          Issue Type: Bug
            Reporter: Claus Ibsen
             Fix For: 4.24.0


Found while adding the catalog body types of plc4x (CAMEL-24961, PR #28411).

h4. 1. A tag value that is not a Map fails with a raw ClassCastException

The producer expects a {{Map<String, Map<String, Object>>}} (tag name to a Map 
of address and value). {{Plc4XProducer.process}} (main 2a465aa4814c, line 77) 
casts the body unchecked, so a body like {{\{t1: 42\}}} fails in 
{{Plc4XEndpoint.buildPlcWriteRequest}} (line 231) with a ClassCastException 
instead of the clear "The body must contain a Map<String,Map<String,Object>" 
error. Checked on 4.24.0-SNAPSHOT with the PLC4X {{simulated://}} driver.

Proposed: check each value is a Map and throw the existing 
{{PlcInvalidTagException}} otherwise.

h4. 2. A value Map with several addresses writes only the first

{{Plc4XEndpoint.buildPlcWriteRequest}} (main 2a465aa4814c, line 231) takes only 
{{keySet().iterator().next()}} of the inner Map, so the other addresses of the 
same tag are ignored without notice. Read in the code, not run.

Proposed: fail when the inner Map has more than one entry (or add each entry), 
and document the expected shape.

h4. 3. The polling consumer throws out of receive() for an unknown tag

{{Plc4XPollingConsumer.doReceive}} (main 2a465aa4814c, line 106) calls 
{{response.getObject(field)}}, which throws a {{PlcRuntimeException}} for a tag 
the PLC does not have. Only {{TimeoutException}}, {{ExecutionException}}, 
{{InterruptedException}} and {{PlcConnectionException}} are caught, so the 
exception is thrown out of {{receive()}} instead of failing the exchange. 
Checked on 4.24.0-SNAPSHOT with the {{simulated://}} driver. The 
{{tagValues()}} method of open PR #28387 (CAMEL-25617) has the same problem.

Proposed: catch it and set it on the exchange, as for the other read failures.

h4. 4. A trigger written with parentheses fails, and the trigger syntax is not 
documented

{{Plc4XConsumer.getScraperConfig}} (main 2a465aa4814c, line 152) wraps the 
{{trigger}} option in parentheses itself, so {{trigger=(RANDOM/b:BOOL)}} 
becomes {{((RANDOM/b:BOOL))==(true)}} and fails with "Invalid trigger strategy 
string". The plc4x doc mentions Triggered Reading but does not say what the 
{{trigger}} value looks like. Checked on 4.24.0-SNAPSHOT with the 
{{simulated://}} driver.

Proposed: strip outer parentheses of the option value, and document the syntax 
with an example ({{trigger=RANDOM/b:BOOL}}).

_Claude Code on behalf of davsclaus_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to