You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Brodie <br...@gmail.com> on 2010/01/15 08:57:24 UTC

Is is a bug to omit the Annotation class?

hi, 
i find that when felix installing a bundle, if the bundle referred to some
other bundle's exported Annotation, and if the Annotation class is not
accessible(for example the annotation class is deleted) , felix omit the
Annotation.
i am not sure if this is a bug, or the JVM runs in this way, but it is
definitely not reasonable. i waste much time on it.

Here is the test, 
public class TestLoadAnnotation {
	@Test
	public void testLoad() throws Exception{
		Felix f = new Felix(new HashMap());
		f.init(); f.start();
		Bundle bundle =
f.getBundleContext().installBundle("file:///home/chi/workspace/profile/target/profile-0.0.1-SNAPSHOT-package.jar");
		bundle.start();
		BundleActivator activator = FelixHelper.getBundleActivator(bundle);
		System.out.println(activator.getClass().getClassLoader());
		Assert.assertTrue(0 != activator.getClass().getAnnotations().length);
	}
}

and the profile bundle's activator definition.
@App("profile")
public class Activator implements BundleActivator{...}

i checked the class file of Activator, and there is this runtime visible
@App annotation. why the annotation is missing?



-- 
View this message in context: http://old.nabble.com/Is-is-a-bug-to-omit-the-Annotation-class--tp27173344p27173344.html
Sent from the Apache Felix - Dev mailing list archive at Nabble.com.


Re: Is is a bug to omit the Annotation class?

Posted by Justin Edelson <ju...@gmail.com>.
Aside from this being the correct behavior (, it sounds like a manifest
problem. If App is in package com.foo.bar, then your bundle needs to import
this package. If that import is not-optional (the default), then the bundle
won't start. If you are concerned about the annotation being deleted from
that package, then require a specific version of the package.

Justin

On Fri, Jan 15, 2010 at 2:57 AM, Brodie <br...@gmail.com> wrote:

>
> hi,
> i find that when felix installing a bundle, if the bundle referred to some
> other bundle's exported Annotation, and if the Annotation class is not
> accessible(for example the annotation class is deleted) , felix omit the
> Annotation.
> i am not sure if this is a bug, or the JVM runs in this way, but it is
> definitely not reasonable. i waste much time on it.
>
> Here is the test,
> public class TestLoadAnnotation {
>        @Test
>        public void testLoad() throws Exception{
>                Felix f = new Felix(new HashMap());
>                f.init(); f.start();
>                Bundle bundle =
>
> f.getBundleContext().installBundle("file:///home/chi/workspace/profile/target/profile-0.0.1-SNAPSHOT-package.jar");
>                bundle.start();
>                BundleActivator activator =
> FelixHelper.getBundleActivator(bundle);
>                System.out.println(activator.getClass().getClassLoader());
>                Assert.assertTrue(0 !=
> activator.getClass().getAnnotations().length);
>        }
> }
>
> and the profile bundle's activator definition.
> @App("profile")
> public class Activator implements BundleActivator{...}
>
> i checked the class file of Activator, and there is this runtime visible
> @App annotation. why the annotation is missing?
>
>
>
> --
> View this message in context:
> http://old.nabble.com/Is-is-a-bug-to-omit-the-Annotation-class--tp27173344p27173344.html
> Sent from the Apache Felix - Dev mailing list archive at Nabble.com.
>
>

Re: Is is a bug to omit the Annotation class?

Posted by Sahoo <Sa...@Sun.COM>.
As Felix said, there is nothing specific about Felix framework here. 
Class.getAnnotations() ignores annotations for which it could not load 
corresponding classes. That's by design. See [1] for example.

Thanks,
Sahoo

[1] 
http://weblogs.java.net/blog/ss141213/archive/2009/10/08/should-classgetannotations-fail-if-annotation-type-not-available

Felix Meschberger wrote:
> Hi,
>
> I am pretty sure that the Felix framework does nothing around annotations.
>
> According to the JavaDoc of the RetentionPolicy annotation, only a
> retention policy of "RUNTIME" ensures an annotation is available at
> runtime. A policy of COMPILE will put it into the class file but the VM
> need not retain it at runtime (this seems to be the default, too).
>
> Regards
> Felix
>
> On 15.01.2010 08:57, Brodie wrote:
>   
>> hi, 
>> i find that when felix installing a bundle, if the bundle referred to some
>> other bundle's exported Annotation, and if the Annotation class is not
>> accessible(for example the annotation class is deleted) , felix omit the
>> Annotation.
>> i am not sure if this is a bug, or the JVM runs in this way, but it is
>> definitely not reasonable. i waste much time on it.
>>
>> Here is the test, 
>> public class TestLoadAnnotation {
>> 	@Test
>> 	public void testLoad() throws Exception{
>> 		Felix f = new Felix(new HashMap());
>> 		f.init(); f.start();
>> 		Bundle bundle =
>> f.getBundleContext().installBundle("file:///home/chi/workspace/profile/target/profile-0.0.1-SNAPSHOT-package.jar");
>> 		bundle.start();
>> 		BundleActivator activator = FelixHelper.getBundleActivator(bundle);
>> 		System.out.println(activator.getClass().getClassLoader());
>> 		Assert.assertTrue(0 != activator.getClass().getAnnotations().length);
>> 	}
>> }
>>
>> and the profile bundle's activator definition.
>> @App("profile")
>> public class Activator implements BundleActivator{...}
>>
>> i checked the class file of Activator, and there is this runtime visible
>> @App annotation. why the annotation is missing?
>>
>>
>>
>>     

Re: Is is a bug to omit the Annotation class?

Posted by Felix Meschberger <fm...@gmail.com>.
Hi,

I am pretty sure that the Felix framework does nothing around annotations.

According to the JavaDoc of the RetentionPolicy annotation, only a
retention policy of "RUNTIME" ensures an annotation is available at
runtime. A policy of COMPILE will put it into the class file but the VM
need not retain it at runtime (this seems to be the default, too).

Regards
Felix

On 15.01.2010 08:57, Brodie wrote:
> 
> hi, 
> i find that when felix installing a bundle, if the bundle referred to some
> other bundle's exported Annotation, and if the Annotation class is not
> accessible(for example the annotation class is deleted) , felix omit the
> Annotation.
> i am not sure if this is a bug, or the JVM runs in this way, but it is
> definitely not reasonable. i waste much time on it.
> 
> Here is the test, 
> public class TestLoadAnnotation {
> 	@Test
> 	public void testLoad() throws Exception{
> 		Felix f = new Felix(new HashMap());
> 		f.init(); f.start();
> 		Bundle bundle =
> f.getBundleContext().installBundle("file:///home/chi/workspace/profile/target/profile-0.0.1-SNAPSHOT-package.jar");
> 		bundle.start();
> 		BundleActivator activator = FelixHelper.getBundleActivator(bundle);
> 		System.out.println(activator.getClass().getClassLoader());
> 		Assert.assertTrue(0 != activator.getClass().getAnnotations().length);
> 	}
> }
> 
> and the profile bundle's activator definition.
> @App("profile")
> public class Activator implements BundleActivator{...}
> 
> i checked the class file of Activator, and there is this runtime visible
> @App annotation. why the annotation is missing?
> 
> 
>