You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Mark Derricutt <ma...@talios.com> on 2008/03/31 06:06:46 UTC

Runtime annotations missing from classes

Hi all,

I've recently started working with OSGi and Apache Felix and have just spent
the afternoon running in circles trying to work out why some code works from
unit tests but not when run from Felix.

>From what I can gather, when classes are loaded up under felix their any run
time annotations present on the classes seemingly disappear.  The particular
code in question (or one of them) comes from within Hibernate:

if ( clazz.isAnnotationPresent( Entity.class ) ) {.....

When running directly from IDEA/TestNG isAnnotationPresent() returns true
for the class, but when I do a remote debug into the code running under
Felix, it returns false (getAnnotations() also returns an empty result).

Is this a known limitation/bug in the Felix classloaders or something I'm
likely to be doing on my side of the code somewhere?

Thanks in advance,
Mark

-- 
"It is easier to optimize correct code than to correct optimized code." --
Bill Harlan

Re: Runtime annotations missing from classes

Posted by Mark Derricutt <ma...@talios.com>.
Cheers, the moment I started reading your post I slapped my head :(
Importing javax.persistence did the trick - now on my next class loading
issue :)

Thanks,
Mark

On Mon, Mar 31, 2008 at 6:54 PM, Stuart McCulloch <
stuart.mcculloch@jayway.net> wrote:

> it's also part of the design of annotations in that annotated classes are
> supposed to continue to load and resolve even if their annotation types
> aren't available on the classpath - this lets you annotate a class with,
> say EJB3 annotations, but also use it in a non-EJB container - where
> you won't then see the EJB3 annotations...
>
>
-- 
"It is easier to optimize correct code than to correct optimized code." --
Bill Harlan

Re: Runtime annotations missing from classes

Posted by Stuart McCulloch <st...@jayway.net>.
On 31/03/2008, Mark Derricutt <ma...@talios.com> wrote:
>
> Hi all,
>
> I've recently started working with OSGi and Apache Felix and have just
> spent
> the afternoon running in circles trying to work out why some code works
> from
> unit tests but not when run from Felix.
>
> From what I can gather, when classes are loaded up under felix their any
> run
> time annotations present on the classes seemingly disappear.  The
> particular
> code in question (or one of them) comes from within Hibernate:
>
> if ( clazz.isAnnotationPresent( Entity.class ) ) {.....
>
> When running directly from IDEA/TestNG isAnnotationPresent() returns true
> for the class, but when I do a remote debug into the code running under
> Felix, it returns false (getAnnotations() also returns an empty result).


sounds like a classloading issue - at runtime the JVM will only return
annotations that are visible to the current classloader, so if your bundle
doesn't import the appropriate package(s) then you won't see them...

Is this a known limitation/bug in the Felix classloaders or something I'm
> likely to be doing on my side of the code somewhere?


it's not a bug as such - more how OSGi classloading works, in that you
can't see classes that you haven't imported (or got via Require-Bundle)
- you'd probably see the same with Equinox or other OSGi frameworks.

it's also part of the design of annotations in that annotated classes are
supposed to continue to load and resolve even if their annotation types
aren't available on the classpath - this lets you annotate a class with,
say EJB3 annotations, but also use it in a non-EJB container - where
you won't then see the EJB3 annotations...

try importing the annotation package inside your bundle and see if that
resolves the problem (or use DynamicImport-Package with a wildcard
if you're not sure which packages you may need to see at runtime)

HTH

Thanks in advance,
> Mark
>
>
> --
> "It is easier to optimize correct code than to correct optimized code." --
> Bill Harlan
>



-- 
Cheers, Stuart