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

@andvasp andvasp commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

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

andvasp commented May 8, 2026

Copy link
Copy Markdown
Contributor Author

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>
@andvasp

andvasp commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

Hi @chrisdutz !

I have done an initial test using your work in refactor/spi3 and looks like this is not happen anymore. I will do more tests and report it!

In your e-mail [SPI3] New CAN, AB-ETH and C-Bus driver. You have done the comment below:
"About AB-ETH and C-Bus I sort of feel we should probably drop them from the repo until we have people using them"

I am using the AB-ETH, inclusive I have done a contributtion to it on #2040. I will also do tests on it too!

Sorry to report the test here. What is the best way to report the test on the refactor/spi3?

The configuration at s7Driver file is incorrect. Perhaps some tests you are doing.

Thanks,
Anderson.

@chrisdutz

Copy link
Copy Markdown
Contributor

Oh wow ... thank you so much for providing feedback at all ;-) I'm happy to hear people are testing things and also that they are using our drivers.

I was sort of expecting to have the bug reports come in as soon as I merge it back to develop because I thought: Nobody is really going to test things till it's in develop. You prove the opposite.

You could leave comments on the PR here ... this way the NLNet folks see that people are using and testing the new driver.

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.

2 participants