jsedding / osgi-ds-metatype-diff

Tool to show the difference in Declarative Services and MetaType metadata of two OSGi bundles
4 stars 3 forks source link

NPE when a bundle is having a metatype file with OCD not containing any AD children #1

Closed kwin closed 5 years ago

kwin commented 5 years ago

I compare two bundles where the old version has a certain metatype file named "OSGI-INF/metatype/file1.xml" but the new bundle does not have it. The old metatype looks like this

<?xml version="1.0" encoding="UTF-8"?><metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0" localization="OSGI-INF/metatype/biz.netcentric.cq.tools.actool.authorizableinstaller.impl.AuthorizableInstallerServiceImpl">
    <OCD id="biz.netcentric.cq.tools.actool.authorizableinstaller.impl.AuthorizableInstallerServiceImpl" name="%biz.netcentric.cq.tools.actool.authorizableinstaller.impl.AuthorizableInstallerServiceImpl.name" description="%biz.netcentric.cq.tools.actool.authorizableinstaller.impl.AuthorizableInstallerServiceImpl.description"/>
    <Designate pid="biz.netcentric.cq.tools.actool.authorizableinstaller.impl.AuthorizableInstallerServiceImpl">
        <Object ocdref="biz.netcentric.cq.tools.actool.authorizableinstaller.impl.AuthorizableInstallerServiceImpl"/>
    </Designate>
</metatype:MetaData>

The following exception is thrown then

19.10.2018 10:49:51 *ERROR* Missing element AD in element OCD
Exception in thread "main" java.lang.NullPointerException
    at net.distilledcode.tools.osgi.Comparison.toOCDMap(Comparison.java:100)
    at net.distilledcode.tools.osgi.Comparison.lambda$nullSafe$12(Comparison.java:228)
    at net.distilledcode.tools.osgi.Comparison.lambda$null$10(Comparison.java:220)
    at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:267)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at net.distilledcode.tools.osgi.Comparison.lambda$tryAll$11(Comparison.java:223)
    at net.distilledcode.tools.osgi.Comparison.valueOrDefault(Comparison.java:213)
    at net.distilledcode.tools.osgi.Comparison.visitAsMap(Comparison.java:194)
    at net.distilledcode.tools.osgi.Comparison.visitMetaType(Comparison.java:68)
    at net.distilledcode.tools.osgi.Comparison.visit(Comparison.java:56)
    at net.distilledcode.tools.osgi.MetadataDiff.diff(MetadataDiff.java:42)
    at net.distilledcode.tools.osgi.MetadataDiff.main(MetadataDiff.java:26)

That is caused by the fact that ocds is null for metatypes not having any ADs.

Basically metatype < 1.3 didn't allow OCD not having any ADs. That was only relaxed in metatype 1.3 (OSGi R6). Unfortunately the maven-scr-plugin creates those invalid XMLs, therefore it would be nice if those edge cases could be covered as well.