Program: 6217
Project: 6217
Buggy source:
@Test public void testAddSystemArtifacts() throws Exception {
  Id.Artifact systemAppArtifactId=Id.Artifact.from(Id.Namespace.SYSTEM,"String_Node_Str","String_Node_Str");
  File systemAppJar=createAppJar(PluginTestApp.class,new File(systemArtifactsDir1,"String_Node_Str"),createManifest(ManifestFields.EXPORT_PACKAGE,PluginTestRunnable.class.getPackage().getName()));
  Id.Artifact pluginArtifactId1=Id.Artifact.from(Id.Namespace.SYSTEM,"String_Node_Str","String_Node_Str");
  Manifest manifest=createManifest(ManifestFields.EXPORT_PACKAGE,TestPlugin.class.getPackage().getName());
  File pluginJar1=createPluginJar(TestPlugin.class,new File(systemArtifactsDir1,"String_Node_Str"),manifest);
  Map<String,PluginPropertyField> emptyMap=Collections.emptyMap();
  Set<PluginClass> manuallyAddedPlugins1=ImmutableSet.of(new PluginClass("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",null,emptyMap),new PluginClass("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",null,emptyMap));
  File pluginConfigFile=new File(systemArtifactsDir1,"String_Node_Str");
  ArtifactConfig pluginConfig1=new ArtifactConfig(ImmutableSet.of(new ArtifactRange(Id.Namespace.SYSTEM,"String_Node_Str",new ArtifactVersion("String_Node_Str"),new ArtifactVersion("String_Node_Str"))),manuallyAddedPlugins1,ImmutableMap.of("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"));
  try (BufferedWriter writer=Files.newWriter(pluginConfigFile,Charsets.UTF_8)){
    writer.write(pluginConfig1.toString());
  }
   Id.Artifact pluginArtifactId2=Id.Artifact.from(Id.Namespace.SYSTEM,"String_Node_Str","String_Node_Str");
  manifest=createManifest(ManifestFields.EXPORT_PACKAGE,TestPlugin.class.getPackage().getName());
  File pluginJar2=createPluginJar(TestPlugin.class,new File(systemArtifactsDir2,"String_Node_Str"),manifest);
  Set<PluginClass> manuallyAddedPlugins2=ImmutableSet.of(new PluginClass("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",null,emptyMap),new PluginClass("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",null,emptyMap));
  pluginConfigFile=new File(systemArtifactsDir2,"String_Node_Str");
  ArtifactConfig pluginConfig2=new ArtifactConfig(ImmutableSet.of(new ArtifactRange(Id.Namespace.SYSTEM,"String_Node_Str",new ArtifactVersion("String_Node_Str"),new ArtifactVersion("String_Node_Str"))),manuallyAddedPlugins2,ImmutableMap.of("String_Node_Str","String_Node_Str"));
  try (BufferedWriter writer=Files.newWriter(pluginConfigFile,Charsets.UTF_8)){
    writer.write(pluginConfig2.toString());
  }
   artifactRepository.addSystemArtifacts();
  Assert.assertTrue(systemAppJar.delete());
  Assert.assertTrue(pluginJar1.delete());
  Assert.assertTrue(pluginJar2.delete());
  try {
    ArtifactDetail appArtifactDetail=artifactRepository.getArtifact(systemAppArtifactId);
    Map<ArtifactDescriptor,List<PluginClass>> plugins=artifactRepository.getPlugins(NamespaceId.DEFAULT,systemAppArtifactId);
    Assert.assertEquals(2,plugins.size());
    List<PluginClass> pluginClasses=plugins.values().iterator().next();
    Set<String> pluginNames=Sets.newHashSet();
    for (    PluginClass pluginClass : pluginClasses) {
      pluginNames.add(pluginClass.getName());
    }
    Assert.assertEquals(Sets.newHashSet("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"),pluginNames);
    Assert.assertEquals(systemAppArtifactId.getName(),appArtifactDetail.getDescriptor().getArtifactId().getName());
    Assert.assertEquals(systemAppArtifactId.getVersion(),appArtifactDetail.getDescriptor().getArtifactId().getVersion());
    ArtifactDetail pluginArtifactDetail=artifactRepository.getArtifact(pluginArtifactId1);
    Assert.assertEquals(pluginArtifactId1.getName(),pluginArtifactDetail.getDescriptor().getArtifactId().getName());
    Assert.assertEquals(pluginArtifactId1.getVersion(),pluginArtifactDetail.getDescriptor().getArtifactId().getVersion());
    Assert.assertTrue(pluginArtifactDetail.getMeta().getClasses().getPlugins().containsAll(manuallyAddedPlugins1));
    Assert.assertEquals(pluginConfig1.getProperties(),pluginArtifactDetail.getMeta().getProperties());
    pluginArtifactDetail=artifactRepository.getArtifact(pluginArtifactId2);
    Assert.assertEquals(pluginArtifactId2.getName(),pluginArtifactDetail.getDescriptor().getArtifactId().getName());
    Assert.assertEquals(pluginArtifactId2.getVersion(),pluginArtifactDetail.getDescriptor().getArtifactId().getVersion());
    Assert.assertTrue(pluginArtifactDetail.getMeta().getClasses().getPlugins().containsAll(manuallyAddedPlugins2));
    Assert.assertEquals(pluginConfig2.getProperties(),pluginArtifactDetail.getMeta().getProperties());
  }
  finally {
    artifactRepository.clear(NamespaceId.SYSTEM);
  }
}

Fixed version (ground truth):
@Test public void testAddSystemArtifacts() throws Exception {
  Id.Artifact systemAppArtifactId=Id.Artifact.from(Id.Namespace.SYSTEM,"String_Node_Str","String_Node_Str");
  File systemAppJar=createAppJar(PluginTestApp.class,new File(systemArtifactsDir1,"String_Node_Str"),createManifest(ManifestFields.EXPORT_PACKAGE,PluginTestRunnable.class.getPackage().getName()));
  Id.Artifact pluginArtifactId1=Id.Artifact.from(Id.Namespace.SYSTEM,"String_Node_Str","String_Node_Str");
  Manifest manifest=createManifest(ManifestFields.EXPORT_PACKAGE,TestPlugin.class.getPackage().getName());
  File pluginJar1=createPluginJar(TestPlugin.class,new File(systemArtifactsDir1,"String_Node_Str"),manifest);
  Map<String,PluginPropertyField> emptyMap=Collections.emptyMap();
  Set<PluginClass> manuallyAddedPlugins1=ImmutableSet.of(new PluginClass("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",null,emptyMap),new PluginClass("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",null,emptyMap));
  File pluginConfigFile=new File(systemArtifactsDir1,"String_Node_Str");
  ArtifactConfig pluginConfig1=new ArtifactConfig(ImmutableSet.of(new ArtifactRange(Id.Namespace.SYSTEM,"String_Node_Str",new ArtifactVersion("String_Node_Str"),new ArtifactVersion("String_Node_Str"))),manuallyAddedPlugins1,ImmutableMap.of("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"));
  try (BufferedWriter writer=Files.newWriter(pluginConfigFile,Charsets.UTF_8)){
    writer.write(pluginConfig1.toString());
  }
   Id.Artifact pluginArtifactId2=Id.Artifact.from(Id.Namespace.SYSTEM,"String_Node_Str","String_Node_Str");
  manifest=createManifest(ManifestFields.EXPORT_PACKAGE,TestPlugin.class.getPackage().getName());
  File pluginJar2=createPluginJar(TestPlugin.class,new File(systemArtifactsDir2,"String_Node_Str"),manifest);
  Set<PluginClass> manuallyAddedPlugins2=ImmutableSet.of(new PluginClass("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",null,emptyMap),new PluginClass("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str",null,emptyMap));
  pluginConfigFile=new File(systemArtifactsDir2,"String_Node_Str");
  ArtifactConfig pluginConfig2=new ArtifactConfig(ImmutableSet.of(new ArtifactRange(Id.Namespace.SYSTEM,"String_Node_Str",new ArtifactVersion("String_Node_Str"),new ArtifactVersion("String_Node_Str"))),manuallyAddedPlugins2,ImmutableMap.of("String_Node_Str","String_Node_Str"));
  try (BufferedWriter writer=Files.newWriter(pluginConfigFile,Charsets.UTF_8)){
    writer.write(pluginConfig2.toString());
  }
   artifactRepository.addSystemArtifacts();
  Assert.assertTrue(systemAppJar.delete());
  Assert.assertTrue(pluginJar1.delete());
  Assert.assertTrue(pluginJar2.delete());
  try {
    ArtifactDetail appArtifactDetail=artifactRepository.getArtifact(systemAppArtifactId);
    Map<ArtifactDescriptor,Set<PluginClass>> plugins=artifactRepository.getPlugins(NamespaceId.DEFAULT,systemAppArtifactId);
    Assert.assertEquals(2,plugins.size());
    Set<PluginClass> pluginClasses=plugins.values().iterator().next();
    Set<String> pluginNames=Sets.newHashSet();
    for (    PluginClass pluginClass : pluginClasses) {
      pluginNames.add(pluginClass.getName());
    }
    Assert.assertEquals(Sets.newHashSet("String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"),pluginNames);
    Assert.assertEquals(systemAppArtifactId.getName(),appArtifactDetail.getDescriptor().getArtifactId().getName());
    Assert.assertEquals(systemAppArtifactId.getVersion(),appArtifactDetail.getDescriptor().getArtifactId().getVersion());
    ArtifactDetail pluginArtifactDetail=artifactRepository.getArtifact(pluginArtifactId1);
    Assert.assertEquals(pluginArtifactId1.getName(),pluginArtifactDetail.getDescriptor().getArtifactId().getName());
    Assert.assertEquals(pluginArtifactId1.getVersion(),pluginArtifactDetail.getDescriptor().getArtifactId().getVersion());
    Assert.assertTrue(pluginArtifactDetail.getMeta().getClasses().getPlugins().containsAll(manuallyAddedPlugins1));
    Assert.assertEquals(pluginConfig1.getProperties(),pluginArtifactDetail.getMeta().getProperties());
    pluginArtifactDetail=artifactRepository.getArtifact(pluginArtifactId2);
    Assert.assertEquals(pluginArtifactId2.getName(),pluginArtifactDetail.getDescriptor().getArtifactId().getName());
    Assert.assertEquals(pluginArtifactId2.getVersion(),pluginArtifactDetail.getDescriptor().getArtifactId().getVersion());
    Assert.assertTrue(pluginArtifactDetail.getMeta().getClasses().getPlugins().containsAll(manuallyAddedPlugins2));
    Assert.assertEquals(pluginConfig2.getProperties(),pluginArtifactDetail.getMeta().getProperties());
  }
  finally {
    artifactRepository.clear(NamespaceId.SYSTEM);
  }
}