Hi,

I recently became aware of the following scenario ( and many thanks to
David Bosschaert for pointing out why it's failing ).

- Bundle A exports package com.foo and registers an adapter factory for
com.foo.Service
- Bundle B imports com.foo from Bundle A and calls
slingRequest.adaptTo(com.foo.Service.class)

When Sling starts up, it's perfectly legal for Bundle B to be STARTED
while Bundle A is just RESOLVED. This means that while com.foo.Service
does not have an AdapterFactory registered, bundle B will call
slingRequest.adaptTo(com.foo.Service.class), which will unexpectedly
return null.

The only 'solution' I see to this is documenting this scenario so that
it's less suprising to others.

I briefly considered using an OSGi manifest header to declare provided
and required adapter factories, but unfortunately you can't always know
what the klazz object will be at runtime when writing

    slingRequest.adaptTo(klazz) 

Thoughts? Other ideas?

Thanks,

Robert

Reply via email to