Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException while starting conditional target bundle #2

Open
amitjoy opened this issue Dec 5, 2020 · 7 comments
Open

ClassCastException while starting conditional target bundle #2

amitjoy opened this issue Dec 5, 2020 · 7 comments

Comments

@amitjoy
Copy link

amitjoy commented Dec 5, 2020

The following exception occurred while starting the conditional target bundle on Felix.

[pool-2-thread-1] ERROR aQute.osgi.conditionaltarget.provider.CTServer - Fail to get the type of the Conditional Target {}
java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.WildcardTypeImpl cannot be cast to java.lang.Class
	at aQute.osgi.conditionaltarget.provider.CTServer.currentRequestedTargets(CTServer.java:124)
	at aQute.osgi.conditionaltarget.provider.CTServer.syncSCR(CTServer.java:87)
	at aQute.osgi.conditionaltarget.provider.Trigger.immediate(Trigger.java:79)
	at aQute.osgi.conditionaltarget.provider.Trigger.schedule(Trigger.java:71)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
@amitjoy
Copy link
Author

amitjoy commented Dec 5, 2020

This happens if we use it with wildcards - ConditionalTarget<?>

@pkriens
Copy link
Member

pkriens commented Dec 6, 2020

But what should it mean?

@amitjoy
Copy link
Author

amitjoy commented Dec 6, 2020

This means that we cannot use wildcards to consume any service type.

@pkriens
Copy link
Member

pkriens commented Dec 6, 2020

It was designed to work for one service type. I guess you could use the wildcard information. What use case do you have in mind?

@amitjoy
Copy link
Author

amitjoy commented Dec 6, 2020

I have a MQTT client that needs to be configured if and only if few services are up and running. That's why I need to use ConditionalTarget to make sure that those user-provided services are ready before the client tries to connect to the broker. For example, javax.net.ssl.TrustManagerFactory needs to be provided as a service so that the client can be configured to use SSL. Similarly, a different API needs to be implemented to intercept the communications between client and the broker. Since all these services are of different types, they cannot be used at all in ConditionalTarget. I have introduced a custom marker API that can be implemented by the aforementioned services so that all of them become the same type and then I can use ConditionalTarget. This works perfectly but I feel it would be really awesome to use wildcards instead of introducing custom marker API for the consumers to implement.

@pkriens
Copy link
Member

pkriens commented Dec 7, 2020

Ok, you make a PR? Shouldn't be too hard?

@amitjoy
Copy link
Author

amitjoy commented Dec 8, 2020

I will surely give it a go :)

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

No branches or pull requests

2 participants