You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@plc4x.apache.org by "fulviosuperga (via GitHub)" <gi...@apache.org> on 2026/04/08 14:52:52 UTC
[I] [Bug]: Cannot invoke "Object.getClass()" because "value" is null
fulviosuperga opened a new issue, #2511:
URL: https://github.com/apache/plc4x/issues/2511
### What happened?
### Description
A NullPointerException occurs in the OPC UA driver when a tag being read from the PLC contains a null value or is uninitialized. Instead of handling the null value gracefully (e.g., returning a PlcNull), the driver attempts to invoke .getClass() on a null object within LegacyPlcValueHandler.
This was observed using PLC4J 0.13.1 integrated with Apache Camel 4.17.0.
### Steps to Reproduce
Setup a PLC with an OPC UA server.
Define a Tag/Node that is present in the address space but has a null value (e.g., an uninitialized DB variable in a Siemens PLC).
Attempt to read this tag using the PLC4J OPC UA driver (via Camel plc4x component or direct PLC4J API).
The driver crashes during the response processing phase.
### Expected Behavior
The driver should detect the null value or a "Bad" status code from the OPC UA response and return a valid PlcValue (like PlcNull) instead of throwing a NullPointerException.
### Environment
PLC4X Version: 0.13.1
Camel Version: 4.17.0
Driver: OPC UA
Java Version: 21 (as per stacktrace refs)
OS: macOS / Linux
### Stacktrace
Java
```
Caused by: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "value" is null
at org.apache.plc4x.java.spi.values.LegacyPlcValueHandler.of(LegacyPlcValueHandler.java:114) ~[plc4j-spi-0.13.1.jar:0.13.1]
at org.apache.plc4x.java.opcua.protocol.OpcuaProtocolLogic.variantToPlcValue(OpcuaProtocolLogic.java:367) ~[plc4j-driver-opcua-0.13.1.jar:0.13.1]
at org.apache.plc4x.java.opcua.protocol.OpcuaProtocolLogic.readResponse(OpcuaProtocolLogic.java:289) ~[plc4j-driver-opcua-0.13.1.jar:0.13.1]
at org.apache.plc4x.java.opcua.protocol.OpcuaProtocolLogic.lambda$9(OpcuaProtocolLogic.java:252) ~[plc4j-driver-opcua-0.13.1.jar:0.13.1]
...
```
### Version
v0.13.1
### Programming Languages
- [ ] plc4c
- [ ] plc4go
- [x] plc4j
- [ ] plc4net
- [ ] plc4py
### Protocols
- [ ] AB-Ethernet
- [ ] ADS /AMS
- [ ] BACnet/IP
- [ ] C-Bus
- [ ] CANopen
- [ ] EtherNet/IP
- [ ] Firmata
- [ ] IEC-69870
- [ ] KNXnet/IP
- [ ] Modbus
- [ ] OPC-UA
- [ ] Profinet
- [x] S7
- [ ] S7-light
--
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] [Bug]: Cannot invoke "Object.getClass()" because "value" is null
Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz commented on issue #2511:
URL: https://github.com/apache/plc4x/issues/2511#issuecomment-5290670628
Using Claude to mass-review open issues after the SPI3 rewrite:
#2511 — NPE "Cannot invoke Object.getClass() because value is null" — the reported crash is gone; the underlying semantics are still not right
- LegacyPlcValueHandler — the class in the stack trace — no longer exists anywhere in the tree. It was removed by the new-SPI rewrite (3725012, Jun
12 2026). The OPC UA driver now uses DefaultPlcValueHandler, and variantToPlcValue constructs PlcValues directly per variant subtype rather than routing
through a generic of(Object).
- A null-valued node no longer throws. OpcuaConnection.readResponse
(plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaConnection.java:474-491) checks dataValue.getValueSpecified(), and an unspecified
value now maps the OPC status code to a PlcResponseCode instead of dereferencing.
What is not handled: a server sending an explicit Null variant (VariantType == 0). That parses cleanly into a generated VariantNull
(protocols/.../opc-manual.mspec:2666, readwrite/Variant.java:102), but variantToPlcValue has no branch for it — the if/else-if chain has no final else, so
it returns null, and the caller reports PlcResponseCode.UNSUPPORTED with a null PlcValue. So the read doesn't crash, but it also doesn't come back as
OK/PlcNull; the caller gets null out of the response. Same in OpcuaSubscriptionHandle.onEventNotification (OpcuaSubscriptionHandle.java:305-306), where a
null event field puts a bare null into the PlcStruct map.
Also note OpcuaConnection.java:482 logs dataValue.getValue().getClass() on the unsupported path — safe for parsed messages (an optional field is non-null
exactly when valueSpecified is true), but it would NPE on a hand-built DataValue, which is reachable from tests.
Your comment on the issue ("feels like curing a symptom") holds up: PlcNull in LegacyPlcValueHandler would have been the wrong layer. The right fix, if
you want one, is a VariantNull branch in variantToPlcValue returning PlcNull (and dropping the null into mapping in the subscription path). I'd suggest
replying on the issue that the NPE is fixed on develop by the SPI rewrite and asking the reporter to confirm against a snapshot — since we still don't
know whether their server sent an unspecified value or a Null variant, and only the latter is still imperfect. Say the word and I'll implement the
VariantNull handling.
-----
I am currently addressing the thing he found however, but that's generally unrelated to the NPE this issue is about.
--
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] [Bug]: Cannot invoke "Object.getClass()" because "value" is null
Posted by "fulviosuperga (via GitHub)" <gi...@apache.org>.
fulviosuperga commented on issue #2511:
URL: https://github.com/apache/plc4x/issues/2511#issuecomment-4207408775
As a temporary workaround, I have successfully resolved the issue in my local environment by shadowing the LegacyPlcValueHandler class.
I can confirm that the NullPointerException occurs at line 114 of LegacyPlcValueHandler.java (version 0.13.1) because the value object is null when the OPC UA server returns an uninitialized or empty variant.
By adding this at line 114:
```
if (value == null) {
return new PlcNull();
}
```
--
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] [Bug]: Cannot invoke "Object.getClass()" because "value" is null
Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz commented on issue #2511:
URL: https://github.com/apache/plc4x/issues/2511#issuecomment-4215333860
Admittedly I'm staying mostly clear of the OPC-UA driver as I didn't write it ... if you could whip up a mergeable PR ... however this thing being null and simply replacing it with a PlcNull sort of feels like curing a symptom.
Is there really a variable being read that has a "null" value? I've never seen any PLC variable ever be NULL.
--
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] [Bug]: Cannot invoke "Object.getClass()" because "value" is null
Posted by "chrisdutz (via GitHub)" <gi...@apache.org>.
chrisdutz closed issue #2511: [Bug]: Cannot invoke "Object.getClass()" because "value" is null
URL: https://github.com/apache/plc4x/issues/2511
--
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