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
getting class cannot be intantiated error
November 24, 2021
14:39, EET
Avatar
pradeep_patel
Member
Members
Forum Posts: 19
Member Since:
July 13, 2021
sp_UserOfflineSmall Offline

I am getting below error when trying to use prosys pubsub sdk with my application and run from some broker. while `samplepubsubsubscriberserver` runs fine when running it as standalone app.

2021-11-24 17:59:53.957 55 java.lang.IllegalArgumentException: The requested (dynamic searched) Class cannot be instantiated: class com.prosysopc.ua.pubsub.PubSubSystem$d
2021-11-24 17:59:53.961 55 at com.prosysopc.ua.pubsub.X.b(SourceFile:354)
2021-11-24 17:59:53.963 55 at com.prosysopc.ua.pubsub.PubSubSystem.start(SourceFile:651)

———————————

November 24, 2021
16:05, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 982
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

Which version and edition of the SDK you are using? What do you mean by “… run from some broker.”?

But in general, if the samples work, but your app does not, find the differences of your code vs. the sample.

There should be a nested exception shown in the stacktrace, can you paste it in full?

November 25, 2021
2:58, EET
Avatar
pradeep_patel
Member
Members
Forum Posts: 19
Member Since:
July 13, 2021
sp_UserOfflineSmall Offline

Hi,
I am using ‘prosys-opc-ua-sdk-for-java-4.6.2-1636-evaluation’.

Below is the error I am getting. I am integrating pubsub component using prosys pubsub sdk in another client where some other pieces of code are running in parallel. Just wanted to know if there is any kind of limitation in such kind of usage which is restricting or causing the sdk to throw this error.

52 * Prosys OPC UA SDK for Java v4.6.2-1636
* (c) Prosys OPC Ltd.

2021-11-25 06:46:49.556 52 * Running in EVALUATION mode
* Connections will close after 120 minutes

2021-11-25 05:52:08.326 52 java.lang.IllegalArgumentException: The requested (dynamic searched) Class cannot be instantiated: class com.prosysopc.ua.pubsub.PubSubSystem$d
2021-11-25 05:52:08.327 52 at com.prosysopc.ua.pubsub.X.b(SourceFile:354)
2021-11-25 05:52:08.328 52 at com.prosysopc.ua.pubsub.PubSubSystem.start(SourceFile:651)
2021-11-25 05:52:08.329 52 at com.pubsub.impl.abc.MyPubSubSystem.run(MyPubSubSystem.java:117)
2021-11-25 05:52:08.331 52 at com.pubsub.impl.abc.MyPubSubSystem.startSubscriber(MyPubSubSystem.java:66)
2021-11-25 05:52:08.333 52 at java.lang.Thread.run(Thread.java:820)
2021-11-25 05:52:08.334 52 Caused by: java.lang.IllegalArgumentException: The requested Class is not bound: class com.prosysopc.ua.pubsub.aw
2021-11-25 05:52:08.336 52 at com.prosysopc.ua.pubsub.X.b(SourceFile:374)
2021-11-25 05:52:08.338 52 at com.prosysopc.ua.pubsub.X.a(SourceFile:524)
2021-11-25 05:52:08.339 52 at com.prosysopc.ua.pubsub.X.b(SourceFile:351)
2021-11-25 05:52:08.340 52 … 5 more
2021-11-25 05:52:08.341 52 java.lang.IllegalArgumentException: The requested (dynamic searched) Class cannot be instantiated: class com.prosysopc.ua.pubsub.PubSubSystem$d
2021-11-25 05:52:08.342 52

2021-11-25 05:52:08.344 52 Shutting down…

November 25, 2021
16:50, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 982
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Did you modify the SDK jar in any way for your app’s build?

Is your app run in an environment where java.util.ServiceLoader would not work? Is it possible to explain what is the environment? Also it’s java version and vendor? Also mentioning just in case it would/could be related (this is the same text as we have in the SDK DL page):
“On Java 11, SDK is only tested in the ‘classpath mode’. It hasn’t been tested in the new ‘module path’ mode and the SDK jar does not include any ‘module-info’ file and it may not work with tools that require this, such as ‘jlink’. “

The PubSub’s internal implementation requires that the jar is as-is regarding internal service files (for the) and that the java.util.ServiceLoader works (such that it seems the SDK jar from inside it). The error would seem to be that no connection factories could be resolved internally (by the SDK, via ServiceLoader) thus we would miss the entire “binding” of them thus the error.

Though we should probably improve on the error reporting in the future..

November 26, 2021
5:22, EET
Avatar
pradeep_patel
Member
Members
Forum Posts: 19
Member Since:
July 13, 2021
sp_UserOfflineSmall Offline

– prosys SDK jar was not modified.
– standalone `SampleSubscriberServer` (It runs fine) and the new Application where I am using the prosys SDK uses the same jdk 1.8.
– pubSubSystem.start(); is throwing this error.
– yes the issue you mention is correct (The error would seem to be that no connection factories could be resolved internally (by the SDK, via ServiceLoader) thus we would miss the entire “binding” of them thus the error.)

can you suggest alternate way of initializing/instantiating pubSubSystem or any changes we can do here to get rid of this error.
—-
try {
pubSubSystem = samplePubSubConfiguration.createPubSubSystem(server, PubSubMode.SUBSCRIBER,
/* variableId */ SamplePubSubConfiguration.SAMPLE_MY_LEVEL_NODE_ID,
/* eventNotifierId */ SamplePubSubConfiguration.SAMPLE_MY_ALARM_NODE_ID,
/* targetVariableId */ SamplePubSubConfiguration.SAMPLE_TARGET_VARIABLE_ID);
// Add the listeners that react to data changes and events
addPubSubEventListeners();
// Starts the PubSubSystem. Note that it must be shutdown separately at the end, as well.
pubSubSystem.start();
startSimulation();
printConnectionAddresses();
mainMenu();
} catch (Exception e) {
printException(e);
}

—–

November 26, 2021
11:06, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 982
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

No ideas for more guesses at least now.. so in short find differences to the sample and fix them (or let us know, maybe it is something we could fix). But in general the design relies on the ServiceLoader to work properly (as it should in normal java environments), so there is like no alternative way to make it work than that.

You can try to put logging on ‘com.prosysopc.ua.pubsub’ on DEBUG, but due to the problem I would not expect it to help much. It should show these normally:
11/26/2021 10:56:37.686 DEBUG [main] com.prosysopc.ua.pubsub.PubSubSystem – Resolving pubsub support modules..
11/26/2021 10:56:37.687 DEBUG [main] com.prosysopc.ua.pubsub.PubSubSystem – Found: [com.prosysopc.ua.pubsub.InternalPubSubUdpSupport$2@3e598df9]
11/26/2021 10:56:37.688 DEBUG [main] com.prosysopc.ua.pubsub.PubSubSystem – Found: [com.prosysopc.ua.pubsub.InternalPubSubUadpSupport$1@32fdec40]
11/26/2021 10:56:37.688 DEBUG [main] com.prosysopc.ua.pubsub.PubSubSystem – Found: [com.prosysopc.ua.pubsub.InternalPubSubMqttSupport$1@29d37757, com.prosysopc.ua.pubsub.U@4fcc529]
11/26/2021 10:56:37.689 DEBUG [main] com.prosysopc.ua.pubsub.PubSubSystem – Found: [com.prosysopc.ua.pubsub.InternalPubSubJsonSupport$1@5d28bcd5]

but I assume in your case due to the problem there is 0 of those Found […] lines.

By ‘standalone `SampleSubscriberServer`’ I assume running from the .bat/.sh scripts. Can you just try to make the sample run in your IDE?

November 26, 2021
12:05, EET
Avatar
pradeep_patel
Member
Members
Forum Posts: 19
Member Since:
July 13, 2021
sp_UserOfflineSmall Offline

On IDE it runs without exception, issue comes when it runs from broker where other pieces of code are running together. Let me debug more around ServiceLoader section when the code gets deployed in my broker and let you know.
It will be helpful if you can comment on the the mandatory list of jars/libraries required when the start method is invoked on PubSubSystem.

November 26, 2021
12:55, EET
Avatar
pradeep_patel
Member
Members
Forum Posts: 19
Member Since:
July 13, 2021
sp_UserOfflineSmall Offline

I saw one folder with name PKI is created when running from IDE. It contains certificates. This folder is not created when deployed from broker and gives the ‘Class cannot be instantiated’ error.

November 26, 2021
14:27, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 982
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

What do you mean by ‘broker’?
Have you read the documentation and the README.txt?
This is explained in the ‘DEPLOYMENT’ section of the README.txt, though seems the mqtt lib part is missing from that.

In short, from the lib folder:
– prosys-opc-ua-sdk-*.jar is the SDK jar and obiviously always needed
– Everything from lib-mandatory is needed
– Everything from lib-opc-https is needed if you enable opc.https endpoints
– Everything from lib-pubsub-mqtt is needed if you want MQTT-UADP or MQTT-JSON connections in PubSub
– Things from lib-samples are only used in the samples and might be needed if your app contains code copied from the samples
– Things from lib-pubsub-samples are only used in pubsub specific samples and might be needed if your app contains code copied from the pubsub samples

Please read everything from the ‘tutorial’ folder and see e.g. the SampleConsoleServer+SampleConsoleClient regarding the certificates etc. stuff.

November 29, 2021
12:25, EET
Avatar
pradeep_patel
Member
Members
Forum Posts: 19
Member Since:
July 13, 2021
sp_UserOfflineSmall Offline

I found this comment in initApplicationIdentity – “Due to SDK design, we must have a certificate in order to have any endpoints”. this is set as client’s application identity.

What are the various options sdk provides for configuring client’s identity. (I assume loading of certificates are mandatory part of identifying client/application and can not be skipped.)

November 29, 2021
13:27, EET
Avatar
pradeep_patel
Member
Members
Forum Posts: 19
Member Since:
July 13, 2021
sp_UserOfflineSmall Offline

If I provide absolute path here, File privateKeyPath = new File(“C:\\prosyssdkcert\\PKI\\CA\\private”); // (initApplicationIdentity method)

it gives me Failed to create session channel to server
Bad_Timeout (code=0x800A0000, description=”The operation timed out.”)
at com.prosysopc.ua.stack.transport.impl.AsyncResultImpl.waitForResult(SourceFile:287)

what is the correct way of specifying path to self signed certificates.

November 29, 2021
14:00, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 982
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Read the tutorials. The are in the ‘tutorial’ folder of the SDK zip you downloaded. Plus check the samples, sampleconsoleclient+sampleconsoleserver and then check the pubsub ones.

If not enough, read at least:
https://reference.opcfoundation.org/Core/docs/Part1/
https://reference.opcfoundation.org/Core/docs/Part2/

December 17, 2021
6:03, EET
Avatar
deepalia
Member
Members
Forum Posts: 5
Member Since:
September 14, 2021
sp_UserOfflineSmall Offline

Hi Bjarne,
We are using a custom class loader, and as you have rightly mentioned in this comment – https://forum.prosysopc.com/forum/opc-ua-java-sdk/getting-class-cannot-be-intantiated-error/#p5766 … with custom class loader following statements are not logged in our case –
DEBUG com.prosysopc.ua.pubsub.PubSubSystem – Found: [com.prosysopc.ua.pubsub.InternalPubSubUdpSupport$2@98bd1627]
DEBUG com.prosysopc.ua.pubsub.PubSubSystem – Found: [com.prosysopc.ua.pubsub.InternalPubSubUadpSupport$1@c595f821]
DEBUG com.prosysopc.ua.pubsub.PubSubSystem – Found: [com.prosysopc.ua.pubsub.InternalPubSubMqttSupport$1@dbefa96, com.prosysopc.ua.pubsub.aa@2ac584ed]
DEBUG com.prosysopc.ua.pubsub.PubSubSystem – Found: [com.prosysopc.ua.pubsub.InternalPubSubJsonSupport$1@6c1c6131]

What is it that is so different for these classes – com.prosysopc.ua.pubsub.InternalPubSubUdpSupport, InternalPubSubUadpSupport, InternalPubSubMqttSupport, InternalPubSubJsonSupport .. that it fails at this point? If you can give us some pointers, it would help us to debug further.

December 17, 2021
11:58, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 982
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Each of those classes extends the package-private internal com.prosysopc.ua.pubsub.AbstractPubSubSupport. PubSubSystem internally loads subtypes of that via java.util.ServiceLoader.load(AbstractPubSubSupport.class). Note that the classes are only public because the ServiceLoader needs them to be.

The java.util.ServiceLoader works by checking the jar’s META-INT/services/com.prosysopc.ua.pubsub.AbstractPubSubSupport file for the implementations, which are
com.prosysopc.ua.pubsub.InternalPubSubUdpSupport
com.prosysopc.ua.pubsub.InternalPubSubUadpSupport
com.prosysopc.ua.pubsub.InternalPubSubMqttSupport
com.prosysopc.ua.pubsub.InternalPubSubJsonSupport

If you have modified the SDK jar via shading or obfuscating, please ensure the file has the updated class names or exclude them from obfuscation.

Each of those can contribute to the internals of PubSubSystem. In the case of the MQTT, as it is optional, it would not contribute anything if the Eclipse Paho cannot be found on the classpath.

The javadocs of ServiceLoader.load(Class),
https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html#load-java.lang.Class-
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/ServiceLoader.html#load(java.lang.Class)

do state “Creates a new service loader for the given service type, using the current thread’s context class loader. ”

So maybe that helps..

We might need to revisit this in the future.

March 14, 2022
6:16, EET
Avatar
deepalia
Member
Members
Forum Posts: 5
Member Since:
September 14, 2021
sp_UserOfflineSmall Offline

Thanks Bjarne. Your inputs helped us to resolve the error. There was some problem with the context class loader settings.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
28 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 75

ibrahim: 75

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: 1466

Posts: 6254

Newest Members:

DavidROunc, fen.pang@woodside.com, aytule, rashadbrownrigg, christi10l, ahamad1, Flores Frederick, ellenmoss, harriettscherer, shanonhumphreys

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

Administrators: admin: 1