Skip to content

fix(plc4j/eip): NullPointerException on decodeSingleReadResponse.#2471

Open
andvasp wants to merge 1 commit into
apache:developfrom
andvasp:fix-eip-NPE-decodeSingleReadResponse
Open

fix(plc4j/eip): NullPointerException on decodeSingleReadResponse.#2471
andvasp wants to merge 1 commit into
apache:developfrom
andvasp:fix-eip-NPE-decodeSingleReadResponse

Conversation

@andvasp
Copy link
Copy Markdown
Contributor

@andvasp andvasp commented Feb 27, 2026

Hi everybody!

I am facing NPE at EipProtocolLogic:::decodeSingleReadResponse because the PlcResponseCode == "INTERNAL_ERROR

╔═CipService════════════════════════════════════════════╗
║╔═response╗╔═service╗╔═CipReadResponse════════════════╗║
║║ b1 true ║║0x4c 76 ║║╔═reserved╗╔═status╗╔═extStatus╗║║
║╚═════════╝╚════════╝║║ 0x00 0  ║║0x05 5 ║║  0x00 0  ║║║
║                     ║╚═════════╝╚═══════╝╚══════════╝║║
║                     ╚════════════════════════════════╝║
╚═══════════════════════════════════════════════════════╝

Caused by: java.lang.NullPointerException: Cannot invoke "org.apache.plc4x.java.eip.readwrite.CIPData.getDataType()" because the return value of "org.apache.plc4x.java.eip.readwrite.CipReadResponse.getData()" is null
at org.apache.plc4x.java.eip.base.protocol.EipProtocolLogic.decodeSingleReadResponse(EipProtocolLogic.java:814)
at org.apache.plc4x.java.eip.base.protocol.EipProtocolLogic.lambda$readWithoutMessageRouter$5(EipProtocolLogic.java:509)
at java.base/java.util.function.Consumer.lambda$andThen$0(Consumer.java:65)
at org.apache.plc4x.java.spi.Plc4xNettyWrapper.decode(Plc4xNettyWrapper.java:194)
at io.netty.handler.codec.MessageToMessageCodec$1.decode(MessageToMessageCodec.java:67)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:91)
at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:120)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)

This pull request just move the type and data to inside the "if" where PlcResponseCode is OK. The data moved is just necessary inside the if to create the plcValue. So it is ok to move the code.

Instead of throwing an exception, the system will report the response code INTERNAL_ERROR and plcValue will be null.

PlcValue null value already can happen on parsePlcValue. So not prejuize to the current logic.

Best regards,
Anderson.

Instead of throwing an exception, the system will report the response code INTERNAL_ERROR and plcValue will be null.
@andvasp
Copy link
Copy Markdown
Contributor Author

andvasp commented May 8, 2026

Hi @chrisdutz!

May you take a look in this simple PR?

Thanks,
Anderson.

spnettec added a commit to spnettec/plc4x that referenced this pull request May 31, 2026
…lc4x

- fix(s7): S7HMuxImpl direct buffer leak per-message (PR apache#2542)
- fix(s7): alarm-query directBuffer not released in S7ProtocolLogic and S7NonHProtocolLogic (PR apache#2543)
- fix(s7,spi): decodeLargeReadResponse heap buffer not released in S7ProtocolLogic and S7NonHProtocolLogic
- feat(spi): SharedExecutor — JVM-scoped thread pools replace per-connection ThreadPoolExecutors to prevent thread accumulation on reconnect (PR apache#2281)
- fix(spi): RequestTransactionManager.shutdown() cancels in-flight requests without shutting down shared executor
- feat(spi): channelInactive lifecycle hook on Plc4xProtocolBase and Plc4xNettyWrapper; all drivers release resources on TCP disconnect (PR apache#2241)
- fix(eip): NPE in decodeSingleReadResponse when PLC returns error status and getData() is null (PR apache#2471)
- fix(umas): align pom version to 0.14.0.B-SNAPSHOT and fix RequestTransactionManager constructor call

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant