Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
uaClient.typeDictionary.refresh() throws TypeCast exception for NodeVersion
June 12, 2023
20:56, EEST
Avatar
hbrackel
Member
Members
Forum Posts: 135
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

Good evening,

when I try to refresh the typeDictionary after a client.connect(), the method uaClient.typeDictionary.refresh() throws a TypeDictionaryException, caused by an attempt to cast an Int to a String when updating a NodeVersion value.

here are the relevant sections of the stack trace:

com.prosysopc.ua.typedictionary.TypeDictionaryException: Cannot init typedictionaries
at com.prosysopc.ua.typedictionary.TypeDictionary.init(SourceFile:471)
at com.prosysopc.ua.typedictionary.TypeDictionary.refresh(SourceFile:493)
[…]
Caused by: java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.String (java.lang.Integer and java.lang.String are in module java.base of loader ‘bootstrap’)
at com.prosysopc.ua.typedictionary.TypeDictionary.b(SourceFile:1063)
at com.prosysopc.ua.typedictionary.TypeDictionary.init(SourceFile:467)
… 14 more

After this exception, any attempt to decode structures fails.

Any clues on how to solve the problem will be much appreciated.

I am (still) using SDK 4.8.0

Thanks,
Hans-Uwe

June 13, 2023
9:18, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 321
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

That particular line of code is attempting to cast the Value of a DataTypeDescriptionType Variable to a java.lang.String, but somehow the Server has returned a java.lang.Integer Value instead and a ClassCastException is thrown. The OPC UA specification defines String as the DataType of DataTypeDescriptionType so Values of other DataTypes are not allowed. For an example of DataTypeDescriptionType Node, see /Root/Types/DataTypes/BaseDataType/Structure/AddNodesItem/Default Binary/AddNodesItem (i=7728). Note, that this BrowsePath includes non-Hierarchical References so you must enable showing them if you try to check this Node in Browser.

If possible, I would recommend fixing the Server to return String Values for all DataTypeDescriptionType Variables. If it is not possible to fix the Server, please let us know and we’ll see if we can add some workaround that would allow accepting non-String Values for DataTypeDescriptionType Variables.

To my knowledge, you have the Client-Server-Source edition of the SDK, so in the meantime you could modify com.prosysopc.ua.typedictionary.TypeDictionary class to handle casting java.lang.Integer to java.lang.String properly. In version 4.8.0, the cast to java.lang.String is on line 1063, so you would need to modify that part of the code to handle Values of other DataTypes in your Client application. You could also add some additional logging such as logging the NodeId of the DataTypeDescriptionType Variable to find which Node or Nodes on the Server are returning non-String Values to make fixing the Server easier.

June 13, 2023
11:43, EEST
Avatar
hbrackel
Member
Members
Forum Posts: 135
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

Thank you very much for your quick reply.

I think I identified the violating server (the application connects to 6 different servers). I am wondering though why the initial automatic call to typeDictionary.init() after connect() does not reveal any problems.

I will connect the vendor of the server about addressing the problem.

Many thanks again, Hans-Uwe

June 13, 2023
12:23, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 321
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

It is quite weird that the automatic call of TypeDictionary.init() did not have the same problem. I was assuming that you might have disabled the automatic call since you were calling the refresh manually, which will first clear some caches and then call init.

If the Client did perform the automatic initializing of TypeDictionary on connecting and only refreshing the TypeDictionary later fails, then perhaps the problematic DataTypeDescriptionType Variable was not yet present on the Server’s AddressSpace when the TypeDictionary was initialized for the first time. Something like that could happen if the Server allowed Clients to connect before it has finished initializing its AddressSpace.

June 13, 2023
13:47, EEST
Avatar
hbrackel
Member
Members
Forum Posts: 135
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

I experimented with the enabling the automatic initialization of the typeDictionary – the setting made no difference in terms of the refresh error.

The custom type definitions may (or may not) indeed not be completed when connecting to the server, but they are known to be complete at the time the refresh() method is called.

June 20, 2023
14:18, EEST
Avatar
hbrackel
Member
Members
Forum Posts: 135
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

Hello again,

I further evaluated the problem and I think that there actually is a bug in the SDK.

The DataTypeDefinition for a custom structured datatype, where a structure component is a single dimension array should look like the following:

Fields […]
– Name: xxx
– Description: xxx
– DataType: some nodeId
– ValueRank : 1
– ArrayDimensions: UInt32 Array[1]. ## here this says the ArrayDimensions array has one element, which is given below
[0] : 0 ## may of course be any number)
– MaxStringLength
– IsOptional: false

These values are more or less directly read from a nodeset.xml file

The Java SDK 4.8.0 shows the following for the same type:

Fields […]
– Name: xxx
– Description: xxx
– DataType: some nodeId
– ValueRank : 1
– ArrayDimensions: UInt32 Array[0]. ## wrong number here – must have one entry for the 1 dimension
– MaxStringLength
– IsOptional: false

The first representation is according to the spec, the second is not, unfortunately. The SDK interprets the ArrayDimension field like in an instance, but not as in a DataTypeDefinitiion.

As this problem is quite urgent for our application, I would appreciate any hint for quick fix.

Thanks,
Hans-Uwe

June 20, 2023
15:23, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 321
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello,

Would it be possible for you to check if this bug has been fixed in the latest release of the SDK, which is currently 4.10.6? Or could you send a NodeSet file with this custom structured datatype to uajava-support@prosysopc.com so that we could test it with the latest version of the SDK?

June 20, 2023
18:04, EEST
Avatar
hbrackel
Member
Members
Forum Posts: 135
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

I updated all libraries to SDK v4.10.6-24 — also this version shows the same problem.

I cannot share the original nodesets, but I will provide a very simple demo nodeset and send it to the address above.

June 30, 2023
14:38, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 321
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

For the benefit of everyone reading this thread,

The problem turned out to be the SDK and the Code Generator not handling ArrayDimensions attributes in NodeSet XML files properly. A fix for this issue will become available in a future release of the SDK.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
14 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

Ibrahim: 76

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 684

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6261

Newest Members:

LouieWreve, Kickbiche, karrimacvitie5, graciela2073, sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma, fidelduke938316

Moderators: Jouni Aro: 1010, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1