You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Cl...@raibau.at on 2009/03/31 08:02:15 UTC

maven-bundle-plugin/bnd and generics

Hello,

I have a class with declares something like 
List<foo.bar.MyClass>. 
For this class, maven-bundle-plugin generates a manifest file without 
foo.bar in the Import-Package list. While this is not a problem at 
runtime, Eclipse says that the class cannot be compiled, because the 
package foo.bar cannot be found.

Can I force maven-bundle-plugin/bnd to consider also the generic types 
when generating the manifest?

Thanks

-- clovis

______________________________________
Diese E-Mail kann vertrauliche und geschuetzte Informationen enthalten. Wenn diese E-Mail nicht für Sie bestimmt ist, bitten wir Sie, uns unverzueglich zu informieren und sie zu loeschen. 

This e-mail message may contain information, which is confidential and protected. If you are not the intended recipient of this message, we ask you to inform us immediately and delete the message afterwards.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Re: Re: maven-bundle-plugin/bnd and generics

Posted by Stuart McCulloch <mc...@gmail.com>.
2009/3/31 <Cl...@raibau.at>

> > this is because you don't actually need it at runtime
> In fact, I do. Even without Eclipse I realized that I got errors because
> the generic information is required at runtime.


well as you have a simple standalone testcase that demonstrates this
please open a JIRA issue and attach it - and feel free to also attach a
suggested patch to bnd :)

this would drastically increase the chance of this being fixed, because
otherwise you'll have to wait for me to get round to making a testcase,
implementing a fix, and finally negotiating the patch with Peter

[ FYI, I am currently between jobs, so no-one is paying me to actively
  work on this - issues with testcases therefore get priority, especially
  if they also contain patches... ]

Here a simplified example:
>
> package b;
>
> import java.lang.reflect.*;
> import a.A;
>
> public class B {
>    java.util.List<A> list;
>
>    public static void main(String[] args) {
>       for(Field f : B.class.getDeclaredFields()) {
>           ParameterizedType type = (ParameterizedType)f.getGenericType();
>           for(Type t : type.getActualTypeArguments()) {
>               System.out.println(t); // <---
> java.lang.TypeNotPresentException: Type a.A not present
>           }
>       }
>    }
> }
>
> I knew about the "workaround"; I wrote the e-mail to the user list after I
> explicitely added the third package, just to be sure that there is not
> better way...
>
> -- clovis
>
> ______________________________________
> Diese E-Mail kann vertrauliche und geschuetzte Informationen enthalten.
> Wenn diese E-Mail nicht für Sie bestimmt ist, bitten wir Sie, uns
> unverzueglich zu informieren und sie zu loeschen.
>
> This e-mail message may contain information, which is confidential and
> protected. If you are not the intended recipient of this message, we ask you
> to inform us immediately and delete the message afterwards.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>


-- 
Cheers, Stuart

Re: Re: Re: maven-bundle-plugin/bnd and generics

Posted by Cl...@raibau.at.
> this is because you don't actually need it at runtime
In fact, I do. Even without Eclipse I realized that I got errors because 
the generic information is required at runtime. Here a simplified example:

package b;

import java.lang.reflect.*;
import a.A;

public class B {
    java.util.List<A> list;

    public static void main(String[] args) {
       for(Field f : B.class.getDeclaredFields()) {
           ParameterizedType type = (ParameterizedType)f.getGenericType();
           for(Type t : type.getActualTypeArguments()) {
               System.out.println(t); // <--- 
java.lang.TypeNotPresentException: Type a.A not present
           }
       }
    }
}

I knew about the "workaround"; I wrote the e-mail to the user list after I 
explicitely added the third package, just to be sure that there is not 
better way...

-- clovis

______________________________________
Diese E-Mail kann vertrauliche und geschuetzte Informationen enthalten. Wenn diese E-Mail nicht für Sie bestimmt ist, bitten wir Sie, uns unverzueglich zu informieren und sie zu loeschen. 

This e-mail message may contain information, which is confidential and protected. If you are not the intended recipient of this message, we ask you to inform us immediately and delete the message afterwards.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Re: maven-bundle-plugin/bnd and generics

Posted by Stuart McCulloch <mc...@gmail.com>.
2009/3/30 <Cl...@raibau.at>

> Generic information does not disappear when the code is compiled, and if
> you disassemble the compiled code you see that the method signature (not
> the method descriptor) contains <foo.bar.MyClass>. So <foo.bar.MyClass> is
> present in the bytecode, and I would like to know if it is possible not to
> ignore this information.
>

there is some generic information left in the bytecode (mainly signatures)
but most is erased - this is because you don't actually need it at runtime

and this is why bnd currently ignores this information - adding such an
import is not required for runtime use and would just pollute the import
space (it would be an artificial dependency just to satisfy one IDE)

adding these imports could also stop your bundle from working when no
bundle exports the packages, which is not correct - your bundle would
work without them

there is a workaround:

  add the package explicitly to your Import-Package instruction

another possibility is adding a switch to bnd to scan generic signatures
(or using the bnd plugin api to extend its scanning algorithm - actually
 this is something I'd like to work on when I have time, to allow people
 to add scanners for hibernate mappings, etc.)

you'd have to convince Peter of the merits of adding such a switch
compared to the current workaround (which doesn't bloat the code)
and providing a suggested patch would probably be a good start

[ yet another option is to bug the Eclipse/PDE people to find out why
  they require an import when it's not required at runtime - I believe
  this is another case of the underlying JDT bug which forces you to
  declare dependencies to make these things visible at both compile
  and runtime ]

-- clovis
>
> ______________________________________
> Diese E-Mail kann vertrauliche und geschuetzte Informationen enthalten.
> Wenn diese E-Mail nicht für Sie bestimmt ist, bitten wir Sie, uns
> unverzueglich zu informieren und sie zu loeschen.
>
> This e-mail message may contain information, which is confidential and
> protected. If you are not the intended recipient of this message, we ask you
> to inform us immediately and delete the message afterwards.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>


-- 
Cheers, Stuart

Re: Re: maven-bundle-plugin/bnd and generics

Posted by Cl...@raibau.at.
Generic information does not disappear when the code is compiled, and if 
you disassemble the compiled code you see that the method signature (not 
the method descriptor) contains <foo.bar.MyClass>. So <foo.bar.MyClass> is 
present in the bytecode, and I would like to know if it is possible not to 
ignore this information.

-- clovis

______________________________________
Diese E-Mail kann vertrauliche und geschuetzte Informationen enthalten. Wenn diese E-Mail nicht für Sie bestimmt ist, bitten wir Sie, uns unverzueglich zu informieren und sie zu loeschen. 

This e-mail message may contain information, which is confidential and protected. If you are not the intended recipient of this message, we ask you to inform us immediately and delete the message afterwards.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: maven-bundle-plugin/bnd and generics

Posted by Clement Escoffier <cl...@gmail.com>.
Hi,

  The <foo.bar.MyClass>  is just present in your Java code, but does  
not exist in the bytecode. However, BND analyzes the bytecode to  
compute required packages. So, it don't find the foo.bar package  
except if you really use it in our code (with a foo.bar.X variable or  
field...).

Regards,

Clement

On 31.03.2009, at 08:02, Clovis.SERAGIOTTO@raibau.at wrote:

> Hello,
>
> I have a class with declares something like
> List<foo.bar.MyClass>.
> For this class, maven-bundle-plugin generates a manifest file without
> foo.bar in the Import-Package list. While this is not a problem at
> runtime, Eclipse says that the class cannot be compiled, because the
> package foo.bar cannot be found.
>
> Can I force maven-bundle-plugin/bnd to consider also the generic types
> when generating the manifest?
>
> Thanks
>
> -- clovis
>
> ______________________________________
> Diese E-Mail kann vertrauliche und geschuetzte Informationen  
> enthalten. Wenn diese E-Mail nicht für Sie bestimmt ist, bitten wir  
> Sie, uns unverzueglich zu informieren und sie zu loeschen.
>
> This e-mail message may contain information, which is confidential  
> and protected. If you are not the intended recipient of this  
> message, we ask you to inform us immediately and delete the message  
> afterwards.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org