[ https://issues.apache.org/jira/browse/FELIX-3407?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Tomas Forsman updated FELIX-3407: --------------------------------- Description: The bundle plugin miss to add imports to classes/interfaces that are used in generic blocks due to type erasure. Consider the following (the code is in the attached zip): bundle-a: package example.a.one; public interface ExampleInterfaceA<T extends ExampleInterfaceB> { String getGreeting(T example); } package example.a.two; public interface ExampleInterfaceB { } bundle-b: package example.b.two; import example.a.two.ExampleInterfaceB; public class ExampleImplementationB implements ExampleInterfaceB { } bundle-c: package example.c; import example.a.one.ExampleInterfaceA; import example.b.two.ExampleImplementationB; public interface ExampleExtendedInterfaceA extends ExampleInterfaceA<ExampleImplementationB> { } package example.c; public class ExampleReferenceListener { public void register(final ExampleExtendedInterfaceA example) { } public void unregister(final ExampleExtendedInterfaceA example) { } } OSGI-INF/blueprint/services.xml <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <reference-list id="exampleReferenceListener" interface="example.c.ExampleExtendedInterfaceA" availability="optional"> <reference-listener bind-method="register" unbind-method="unregister"> <bean class="example.c.ExampleReferenceListener"/> </reference-listener> </reference-list> </blueprint> bundle-d: package example.d; import example.b.two.ExampleImplementationB; import example.c.ExampleExtendedInterfaceA; public class ExampleExtendedImplementation implements ExampleExtendedInterfaceA { public String getGreeting(final ExampleImplementationB example) { return "Hello World"; } } OSGI-INF/blueprint/services.xml <?xml version="1.0" encoding="UTF-8"?> <blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <bean id="exampleBean" class="example.d.ExampleExtendedImplementation"/> <service id="exampleService" interface="example.c.ExampleExtendedInterfaceA" ref="exampleBean"/> </blueprint> Since the bundle plugin uses byte-code to find out which imports to add to the manifest, the bundle-c manifest look like this: Manifest-Version: 1.0 Bnd-LastModified: 1332925553008 Build-Jdk: 1.6.0_26 Built-By: tofo01 Bundle-ManifestVersion: 2 Bundle-Name: example.bundle-c Bundle-SymbolicName: example.bundle-c Bundle-Version: 1.0.0.SNAPSHOT Created-By: Apache Maven Bundle Plugin Export-Package: example.c;uses:="example.a.one";version="1.0.0.SNAPSHOT" Import-Package: example.a.one;version="[1.0,2)",org.osgi.service.blueprint;version="[1.0.0,2.0.0)" Import-Service: example.c.ExampleExtendedInterfaceA;multiple:=true;availability:=optional Tool: Bnd-1.50.0 The "example.a.two" package import is missing since type-erasure removes the generic part of ExampleInterfaceA in the bundle-c interface. This results in a NoClassDefFondError of example.a.two.ExampleInterfaceB from bundle-c when trying to deploy bundle-d. "Error tracking new service reference java.lang.NoClassDefFoundError: example.a.two.ExampleInterfaceB not found by example.bundle-c [159]" Summary: Imports are missed for generics (was: Iimport for generics) > Imports are missed for generics > ------------------------------- > > Key: FELIX-3407 > URL: https://issues.apache.org/jira/browse/FELIX-3407 > Project: Felix > Issue Type: Bug > Components: Maven Bundle Plugin > Affects Versions: maven-bundle-plugin-2.3.7 > Reporter: Tomas Forsman > > The bundle plugin miss to add imports to classes/interfaces that are used in > generic blocks due to type erasure. > Consider the following (the code is in the attached zip): > bundle-a: > package example.a.one; > public interface ExampleInterfaceA<T extends ExampleInterfaceB> { > String getGreeting(T example); > } > package example.a.two; > public interface ExampleInterfaceB { > } > bundle-b: > package example.b.two; > import example.a.two.ExampleInterfaceB; > public class ExampleImplementationB implements ExampleInterfaceB { > } > bundle-c: > package example.c; > import example.a.one.ExampleInterfaceA; > import example.b.two.ExampleImplementationB; > public interface ExampleExtendedInterfaceA extends > ExampleInterfaceA<ExampleImplementationB> { > } > package example.c; > public class ExampleReferenceListener { > public void register(final ExampleExtendedInterfaceA example) { > } > public void unregister(final ExampleExtendedInterfaceA example) { > } > } > OSGI-INF/blueprint/services.xml > <?xml version="1.0" encoding="UTF-8"?> > <blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" > xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 > http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> > <reference-list id="exampleReferenceListener" > interface="example.c.ExampleExtendedInterfaceA" > availability="optional"> > <reference-listener bind-method="register" unbind-method="unregister"> > <bean class="example.c.ExampleReferenceListener"/> > </reference-listener> > </reference-list> > </blueprint> > bundle-d: > package example.d; > import example.b.two.ExampleImplementationB; > import example.c.ExampleExtendedInterfaceA; > public class ExampleExtendedImplementation implements > ExampleExtendedInterfaceA { > public String getGreeting(final ExampleImplementationB example) { > return "Hello World"; > } > } > OSGI-INF/blueprint/services.xml > <?xml version="1.0" encoding="UTF-8"?> > <blueprint xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" > xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 > http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> > <bean id="exampleBean" class="example.d.ExampleExtendedImplementation"/> > <service id="exampleService" > interface="example.c.ExampleExtendedInterfaceA" ref="exampleBean"/> > </blueprint> > Since the bundle plugin uses byte-code to find out which imports to add to > the manifest, the bundle-c manifest look like this: > Manifest-Version: 1.0 > Bnd-LastModified: 1332925553008 > Build-Jdk: 1.6.0_26 > Built-By: tofo01 > Bundle-ManifestVersion: 2 > Bundle-Name: example.bundle-c > Bundle-SymbolicName: example.bundle-c > Bundle-Version: 1.0.0.SNAPSHOT > Created-By: Apache Maven Bundle Plugin > Export-Package: example.c;uses:="example.a.one";version="1.0.0.SNAPSHOT" > Import-Package: > example.a.one;version="[1.0,2)",org.osgi.service.blueprint;version="[1.0.0,2.0.0)" > Import-Service: > example.c.ExampleExtendedInterfaceA;multiple:=true;availability:=optional > Tool: Bnd-1.50.0 > The "example.a.two" package import is missing since type-erasure removes the > generic part of ExampleInterfaceA in the bundle-c interface. > This results in a NoClassDefFondError of example.a.two.ExampleInterfaceB from > bundle-c when trying to deploy bundle-d. > "Error tracking new service reference java.lang.NoClassDefFoundError: > example.a.two.ExampleInterfaceB not found by example.bundle-c [159]" -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira