Friday, August 06, 2010

[SCR] Found components with duplicated names inside their bundle!

Today I was briefly confused by an error message issued by the OSGi Equinox runtime’s Declarative Services runtime which I did not understand immediately. For your – and my own – reference find the solution here.
First, this was the error message I got:
1281104579615=1::[SCR] Found components with duplicated names inside their bundle!
 This component will not be processed: Component[
    name = networksimulation
    factory = null
    autoenable = true
    immediate = true
    implementation = com.danielschneller.sim.network.NetworkStateSimulation
    properties = {devicevendor=DanielSchneller, simulation=true}
    serviceFactory = false
    serviceInterface = [com.danielschneller.network.NetworkState]
    references = {
        Reference[name = LOG, interface = org.osgi.service.log.LogService, 
        policy = static, cardinality = 0..1, target = null, bind = null, unbind = null]
    }
    located in bundle = com.danielschneller.sim.network_1.1.0.qualifier [49]
]
Apparently the component name networksimulation was used by two components in the same bundle. Well, that’s why you are encouraged to use package-name like identifiers; however this was not the problem. Changing it to com.danielschneller.sim.net.simulation which was guaranteed to be unique in my case still left the error the same:
1281104579615=1::[SCR] Found components with duplicated names inside their bundle!
This component will not be processed: Component[
    name = com.danielschneller.sim.net.simulation
    factory = null
    ...
To make it short, this is what happened: I had added this component’s description to a bundle that already contained some more using the Eclipse wizard for new service components.
That very fine wizard dutifully added the new filename to the Manifest is the Service-Component: line. Unfortunately in this case it led to:
Service-Component: OSGI-INF/*.xml, networksimulation.xml
At launch time apparently the wildcard was expanded, already including the new file, and then added at the end again. Apparently there is no sanitizing done (like adding the filenames to a Set instead of a List), which results in a second attempt of registering the same component a second time. I will go and file a bug with Eclipse for this, There already is a filed, but unfixed bug for this (Eclipse Bug #278540) but till then just make sure that when you use wildcards in the Service-Component Manifest header it does not cause any duplicates.

3 comments:

guido said...

Thanks your blog post saved my day!

Anonymous said...

Thank I got the same problem with the annotation generation which duplicate the name of the component.xml

Anonymous said...

Thanks, you saved me a lot of debugging...!