diff --git a/biz.aQute.bndlib.tests/test/test/metatype/SpecMetatypeTest.java b/biz.aQute.bndlib.tests/test/test/metatype/SpecMetatypeTest.java index 7ac3e4f851..c27a028f55 100644 --- a/biz.aQute.bndlib.tests/test/test/metatype/SpecMetatypeTest.java +++ b/biz.aQute.bndlib.tests/test/test/metatype/SpecMetatypeTest.java @@ -321,6 +321,7 @@ public interface DupPid4 { } + // this is allowed (no duplicate) @ObjectClassDefinition(pid = { "3" }, factoryPid = { @@ -330,6 +331,7 @@ public interface DupPid5 { } + // this is allowed (no duplicate) @ObjectClassDefinition(pid = { "4" }) @@ -337,6 +339,7 @@ public interface DupPid6 { } + // this is allowed (no duplicate) @ObjectClassDefinition(factoryPid = { "4" }) @@ -354,7 +357,7 @@ public void testPidCollision() throws Exception { b.setProperty(Constants.METATYPE_ANNOTATIONS, name.substring(0, name.length() - "1".length()) + "*"); b.build(); System.err.println(b.getErrors()); - assertEquals(4, b.getErrors() + assertEquals(2, b.getErrors() .size()); } diff --git a/biz.aQute.bndlib/src/aQute/bnd/metatype/MetatypeAnnotations.java b/biz.aQute.bndlib/src/aQute/bnd/metatype/MetatypeAnnotations.java index 7aaa361456..3224ba1bc6 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/metatype/MetatypeAnnotations.java +++ b/biz.aQute.bndlib/src/aQute/bnd/metatype/MetatypeAnnotations.java @@ -105,6 +105,7 @@ public boolean analyzeJar(Analyzer analyzer) throws Exception { Set ocdIds = new HashSet<>(); Set pids = new HashSet<>(); + Set factoryPids = new HashSet<>(); Instructions instructions = new Instructions(header); @@ -142,8 +143,10 @@ public boolean analyzeJar(Analyzer analyzer) throws Exception { analyzer.error("Duplicate OCD id %s from class %s; known ids %s", definition.id, c.getFQN(), ocdIds); } for (DesignateDef dDef : definition.designates) { - if (dDef.pid != null && !pids.add(dDef.pid)) { - analyzer.error("Duplicate pid %s from class %s", dDef.pid, c.getFQN()); + Set relevantPids = dDef.factory ? factoryPids : pids; + if (dDef.pid != null && !relevantPids.add(dDef.pid)) { + analyzer.error("Duplicate %s from class %s", dDef.factory ? "factoryPid" : "pid", dDef.pid, + c.getFQN()); } } String name = "OSGI-INF/metatype/" + analyzer.validResourcePath(definition.id, "Invalid resource name")