Skip to content

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

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

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

Conversation

@andvasp
Copy link
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.
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