Issue Details (XML | Word | Printable)

Key: OSGI-484
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Costin Leau
Reporter: Costin Leau
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring OSGi

Equinox expects its own ServiceReference implementation

Created: 12/May/08 04:08 AM   Updated: 15/Jul/08 03:36 PM
Component/s: CORE
Affects Version/s: 1.1 M2
Fix Version/s: 1.1 RC1

Time Tracking:
Not Specified


 Description  « Hide
See: http://www.springsource.com/beta/applicationplatform/comments.php?DiscussionID=53&page=1#Item_0


If I inject ServiceReference and BundleContext into a bean, and try to resolve it to a service interface at runtime using something like:

EchoService test = (EchoService) bundleContext.getService(serviceReference);

- it fails with the following error:

java.lang.ClassCastException: org.springframework.osgi.service.importer.support.ServiceReferenceDelegate
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.getService(BundleContextImpl.java:890)
at b3.impl.ClientServiceImpl.getEchoService(ClientServiceImpl.java:33)
at b3.impl.ClientServiceImpl$1.run(ClientServiceImpl.java:23)

The problem is in the org.eclipse.osgi codebase, where it assumes that the incoming object will be their custom implementation..

class BundleContextImpl:
public Object getService(org.osgi.framework.ServiceReference reference) {
...
ServiceRegistrationImpl registration = ((ServiceReferenceImpl) reference).registration;
...
}

 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Reto Urfer added a comment - 08/Jul/08 01:51 AM
I have installed now the official 1.1.0 release and run exactly into the problem described.

So it seems it is NOT fixed!

Reto Urfer added a comment - 08/Jul/08 11:19 AM
The difference in my case:

I got an instance of StaticServiceReferenceProxy injected through the onBind method of a OSGi service listener instead of a ServiceReferenceDelegate object.

Olof Jönsson added a comment - 14/Jul/08 06:37 AM
No, it is not fixed in 1.1.0 since I get the same exact problem as Reto above.

Although I haven't seen anything in the specs that would explicitly allow Spring to pass a different instance of ServiceReference to the framework than one that was gotten from it earlier, I don't see that there would have to be a problem with doing it either. Therefore, I consider this a bug/improvement on the Equinox side of things and has filed bug 240659 there (https://bugs.eclipse.org/bugs/show_bug.cgi?id=240659).

Olof Jönsson added a comment - 15/Jul/08 01:03 AM
Apparently, there are restrictions on the equals() and hashCode()-methods on ServiceReference in the OSGi spec that prevents proxying of them. Specifically, the equals()-methods must return true if they refer to the same service and by consequence the hashCode()-methods need to give the same value. Since the logic for the equals() and hashCode()-methods isn't specified it isn't possible to proxy them which makes this a bug.

Olof Jönsson added a comment - 15/Jul/08 03:36 PM
I've created a new issue (a bug this time) for this at http://jira.springframework.org/browse/OSGI-582