You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@plc4x.apache.org by "chrisdutz (via GitHub)" <gi...@apache.org> on 2026/09/11 11:15:09 UTC

[I] S7: reading a BOOL array fails with NullPointerException in PlcBOOL.of, tag returns INTERNAL_ERROR

chrisdutz opened a new issue, #2742:
URL: https://github.com/apache/plc4x/issues/2742

   ## What happens
   
   Reading a `BOOL` array tag from a non-optimized data block on an S7-1500 fails. The tag comes back
   with response code `INTERNAL_ERROR` and no value; the driver logs a `NullPointerException` while
   decoding. Scalar `BOOL` reads from the same block work, and so do arrays of every other type I
   tried (`BYTE`, `INT`, `UINT`, `DINT`, `LREAL`, `TIME`, `STRING`).
   
   ## Versions
   
   - PLC4X 1.0.0 (`plc4j-driver-s7`, `plc4j-spi-values`, `plc4j-spi-drivers`)
   - Java 21, macOS 15 (aarch64)
   - Device: S7-1500 (CPU 1511-C PN), classic protocol, non-optimized block access
   
   ## Steps to reproduce
   
   Read an array of BOOL from a non-optimized DB:
   
   ```java
   PlcConnection connection = new DefaultPlcDriverManager().getConnection("s7://192.168.0.1");
   PlcReadRequest request = connection.readRequestBuilder()
       .addTagAddress("bools", "%DB42:214.0[1..8;1]:BOOL")
       .build();
   PlcReadResponse response = request.execute().get();
   System.out.println(response.getResponseCode("bools")); // INTERNAL_ERROR
   ```
   
   `%DB42:216.0[0..7]:BYTE` against the same block succeeds, as does the scalar `%DB42:0.0:BOOL`,
   so the connection and the block itself are fine.
   
   ## Stack trace
   
   ```
   WARN  o.apache.plc4x.java.s7.S7CotpConnection : Error decoding tag %DB42:214.0[1..8;1]:BOOL
   
   java.lang.NullPointerException: Cannot invoke "Object.toString()" because "value" is null
       at org.apache.plc4x.java.spi.values.PlcBOOL.of(PlcBOOL.java:65)
       at org.apache.plc4x.java.spi.values.DefaultPlcValueHandler.ofElement(DefaultPlcValueHandler.java:139)
       at org.apache.plc4x.java.spi.values.DefaultPlcValueHandler.ofElements(DefaultPlcValueHandler.java:116)
       at org.apache.plc4x.java.spi.values.DefaultPlcValueHandler.of(DefaultPlcValueHandler.java:86)
       at org.apache.plc4x.java.s7.S7CotpConnection.parsePlcValue(S7CotpConnection.java:995)
       at org.apache.plc4x.java.s7.S7CotpConnection.decodeBindingInto(S7CotpConnection.java:736)
       at org.apache.plc4x.java.s7.S7CotpConnection.applyChunkResponse(S7CotpConnection.java:699)
       at org.apache.plc4x.java.s7.S7CotpConnection.lambda$sendReadChunk$1(S7CotpConnection.java:649)
       at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:955)
       ...
       at org.apache.plc4x.java.spi.drivers.throttle.RequestThrottle.lambda$start$0(RequestThrottle.java:121)
   ```
   
   ## Analysis
   
   Two things seem to be in play, and I suspect only the first is the actual bug:
   
   1. **The element values reaching the value handler are null.** `DefaultPlcValueHandler.ofElements`
      iterates the `Object[]` it is handed and calls `ofElement` per entry, so at least one entry is
      null by the time it gets there. That points at the S7 side (`S7CotpConnection.parsePlcValue` /
      `decodeBindingInto`) producing a shorter or sparsely-filled value array for packed BOOL arrays
      than the declared element count — plausible since BOOLs are bit-packed and every other,
      byte-aligned, array type decodes correctly. I have not confirmed this in a debugger, so treat
      the exact mechanism as a guess; the null element itself is certain from the trace.
   
   2. **`PlcBOOL.of(Object)` has no null guard.** Its chain of `instanceof` checks all fail for null
      and it falls through to `return new PlcBOOL(value.toString())`, which is where the NPE is
      thrown. Even once the S7 decoding is fixed, a null here would be better off as a clear
      `PlcInvalidTagException`/`IllegalArgumentException` than an NPE — the other `Plc*.of` factories
      share this shape, so it is a general robustness point rather than something specific to BOOL.
   
   ## Impact
   
   Because the exception is caught and mapped to a bare `INTERNAL_ERROR` response code, and PLC4X
   exposes no per-tag exception on `PlcReadResponse`, a caller sees only the enum constant — the
   stack trace is reachable only in the driver's own log. Surfacing the cause per tag (an optional
   `Throwable` alongside the response code) would make failures like this far easier to diagnose,
   though that is a separate enhancement from the bug above.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] S7: reading a BOOL array fails with NullPointerException in PlcBOOL.of, tag returns INTERNAL_ERROR

Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz commented on issue #2742:
URL: https://github.com/apache/plc4x/issues/2742#issuecomment-5633626087

   Disclaimer: I was playing around with something and claude diagnosed a bug in PLC4X and asked me if we want to report that ... was curuous how that would work (He opened a remote controlled chrome tab and did all the clickety-clickety but wanted me to click the submit button)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] S7: reading a BOOL array fails with NullPointerException in PlcBOOL.of, tag returns INTERNAL_ERROR

Posted by "sruehl (via GitHub)" <gi...@apache.org>.
sruehl commented on issue #2742:
URL: https://github.com/apache/plc4x/issues/2742#issuecomment-5634167125

   My gut tells me this is more like this debug dump you would get from a browser when stuff goes south. So not really API worthy IMHO as the dev can't change it anway...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] S7: reading a BOOL array fails with NullPointerException in PlcBOOL.of, tag returns INTERNAL_ERROR

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on issue #2742:
URL: https://github.com/apache/plc4x/issues/2742#issuecomment-6435773613

   We see the same with PLC4X 1.0.0 from Apache Camel (camel-plc4x, CAMEL-25617), on a Siemens S7-1200 (CPU 1214C) and also against the snap7 1.4.2 server, so it reproduces without real hardware. Reading `%DB1.DBX16.0[0..7]:BOOL` returns `INTERNAL_ERROR`, but here the driver fails with a `BufferUnderflowException` instead of the NPE in `PlcBOOL.of`. Scalar BOOLs and arrays of the other types read fine from the same block. It looks like the same bit-packed BOOL array decoding problem, reached through a different path.
   
   _Claude Code on behalf of davsclaus_
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] S7: reading a BOOL array fails with NullPointerException in PlcBOOL.of, tag returns INTERNAL_ERROR

Posted by "sruehl (via GitHub)" <gi...@apache.org>.
sruehl closed issue #2742: S7: reading a BOOL array fails with NullPointerException in PlcBOOL.of, tag returns INTERNAL_ERROR
URL: https://github.com/apache/plc4x/issues/2742


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] S7: reading a BOOL array fails with NullPointerException in PlcBOOL.of, tag returns INTERNAL_ERROR

Posted by "etzel-mes (via GitHub)" <gi...@apache.org>.
etzel-mes commented on issue #2742:
URL: https://github.com/apache/plc4x/issues/2742#issuecomment-6435938188

   Here is the `BufferUnderflowException` trace, from PLC4X 1.0.0 reading `%DB1.DBX16.0[0..7]:BOOL` on a real S7-1200 (CPU 1214C, a DB with optimized block access off, `s7://<plc>?controller-type=S7_1200&cotp.remote-rack=0&cotp.remote-slot=1&pdu-size=240`, Java 25 on macOS). The snap7 1.4.2 server gives the same log, line for line.
   
   The log has both exceptions, in this order: element 0 decodes, each of elements 1 to 7 logs `Error parsing element N of tag BOOL` with a `BufferUnderflowException`, and then the `NullPointerException` from the description follows. (My summary on the Camel PR named only the first one.)
   
   ```
   2026-10-24 12:49:05.491 WARN  [TCP-Read-localhost:11102] o.a.p.j.s.S7CotpConnection - Error parsing element 1 of tag BOOL
   org.apache.plc4x.java.spi.buffers.api.exceptions.BufferUnderflowException: Not enough bits left to read
   	at org.apache.plc4x.java.spi.buffers.bytebased.AbstractBufferByteBased.ensureAvailable(AbstractBufferByteBased.java:195)
   	at org.apache.plc4x.java.spi.buffers.bytebased.ReadBufferByteBased.readUnsignedByte(ReadBufferByteBased.java:124)
   	at org.apache.plc4x.java.spi.fields.data.reader.DataReaderSimpleUnsignedByte.read(DataReaderSimpleUnsignedByte.java:34)
   	at org.apache.plc4x.java.spi.fields.data.reader.DataReaderSimpleUnsignedByte.read(DataReaderSimpleUnsignedByte.java:26)
   	at org.apache.plc4x.java.spi.fields.fields.reader.FieldReaderReserved.readReservedField(FieldReaderReserved.java:42)
   	at org.apache.plc4x.java.spi.fields.fields.reader.FieldReaderFactory.readReservedField(FieldReaderFactory.java:124)
   	at org.apache.plc4x.java.s7.readwrite.DataItem.staticParse(DataItem.java:76)
   	at org.apache.plc4x.java.s7.S7CotpConnection.lambda$parsePlcValue$24(S7CotpConnection.java:988)
   	at java.base/java.util.stream.IntPipeline$1$1.accept(IntPipeline.java:180)
   	at java.base/java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:104)
   	at java.base/java.util.Spliterator$OfInt.forEachRemaining(Spliterator.java:710)
   	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:570)
   	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:560)
   	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:635)
   	at java.base/java.util.stream.AbstractPipeline.evaluateToArrayNode(AbstractPipeline.java:291)
   	at java.base/java.util.stream.ReferencePipeline.toArray(ReferencePipeline.java:652)
   	at org.apache.plc4x.java.s7.S7CotpConnection.parsePlcValue(S7CotpConnection.java:994)
   	at org.apache.plc4x.java.s7.S7CotpConnection.decodeBindingInto(S7CotpConnection.java:736)
   	at org.apache.plc4x.java.s7.S7CotpConnection.applyChunkResponse(S7CotpConnection.java:699)
   	at org.apache.plc4x.java.s7.S7CotpConnection.lambda$sendReadChunk$19(S7CotpConnection.java:649)
   	at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:955)
   	at java.base/java.util.concurrent.CompletableFuture$UniHandle.tryFire(CompletableFuture.java:932)
   	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:531)
   	at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2206)
   	at org.apache.plc4x.java.spi.drivers.throttle.RequestThrottle.lambda$start$1(RequestThrottle.java:121)
   	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:884)
   	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:862)
   	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:531)
   	at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2206)
   	at org.apache.plc4x.java.s7.S7CotpConnection.handleIncomingMessage(S7CotpConnection.java:502)
   	at org.apache.plc4x.java.spi.drivers.MessageCodecBase.processIncomingData(MessageCodecBase.java:200)
   	at org.apache.plc4x.java.s7.S7CotpConnection.lambda$onConnect$0(S7CotpConnection.java:190)
   	at org.apache.plc4x.java.transport.cotp.CotpTransportInstance.lambda$setupAsyncEventPropagation$0(CotpTransportInstance.java:124)
   	at org.apache.plc4x.java.transport.tcp.TcpTransportInstance.safeRun(TcpTransportInstance.java:374)
   	at org.apache.plc4x.java.transport.tcp.TcpTransportInstance.runReadLoop(TcpTransportInstance.java:423)
   	at java.base/java.lang.VirtualThread.run(VirtualThread.java:460)
   ... the same warning and trace for elements 2 to 7 ...
   2026-10-24 12:49:05.494 WARN  [TCP-Read-localhost:11102] o.a.p.j.s.S7CotpConnection - Error decoding tag bools16
   java.lang.NullPointerException: Cannot invoke "Object.toString()" because "value" is null
   	at org.apache.plc4x.java.spi.values.PlcBOOL.of(PlcBOOL.java:65)
   	at org.apache.plc4x.java.spi.values.DefaultPlcValueHandler.ofElement(DefaultPlcValueHandler.java:139)
   	at org.apache.plc4x.java.spi.values.DefaultPlcValueHandler.ofElements(DefaultPlcValueHandler.java:116)
   	at org.apache.plc4x.java.spi.values.DefaultPlcValueHandler.of(DefaultPlcValueHandler.java:86)
   	at org.apache.plc4x.java.s7.S7CotpConnection.parsePlcValue(S7CotpConnection.java:995)
   	at org.apache.plc4x.java.s7.S7CotpConnection.decodeBindingInto(S7CotpConnection.java:736)
   	at org.apache.plc4x.java.s7.S7CotpConnection.applyChunkResponse(S7CotpConnection.java:699)
   	at org.apache.plc4x.java.s7.S7CotpConnection.lambda$sendReadChunk$19(S7CotpConnection.java:649)
   	at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:955)
   	...
   ```
   
   In the 1.0.0 source, for an array that is not `BYTE`, `S7CotpConnection.parsePlcValue` calls `DataItem.staticParse` once per element on the same buffer (line 988). For `BOOL` that reads seven reserved bits and then the value bit, so eight bits per element, while the reply carried a single byte for the eight BOOLs. Element 0 consumes that byte, elements 1 to 7 hit the end of the buffer, the catch at line 991 logs them and leaves them null, and `DefaultPlcValueHandler.of` at line 995 throws the NPE. So it is one decoding path, and the null elements in point 1 of the description come from line 988.
   
   Against snap7, `%DB1.DBX16.0[0..1]:BOOL` fails the same way on element 1, and the single element `%DB1.DBX16.0[1]:BOOL` (the one-element branch at line 980) reads fine.
   
   _Claude Code on behalf of etzel-mes_
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] S7: reading a BOOL array fails with NullPointerException in PlcBOOL.of, tag returns INTERNAL_ERROR

Posted by "kVinsom (via GitHub)" <gi...@apache.org>.
kVinsom commented on issue #2742:
URL: https://github.com/apache/plc4x/issues/2742#issuecomment-6348925399

   I'd like to work on this issue. I'll start by reproducing the BOOL array decoding failure, investigate the S7 bit-packed payload handling, and add regression tests with the fix.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org