Program: 5730
Project: 5730
Buggy source:
@Test public void testPluginSelector() throws Exception {
  try {
    artifactRepository.findPlugin(NamespaceId.DEFAULT,APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector());
    Assert.fail();
  }
 catch (  PluginNotExistsException e) {
  }
  File pluginDir=DirUtils.createTempDir(tmpDir);
  Id.Artifact artifact1Id=Id.Artifact.from(Id.Namespace.DEFAULT,"String_Node_Str","String_Node_Str");
  Manifest manifest=createManifest(ManifestFields.EXPORT_PACKAGE,TestPlugin.class.getPackage().getName());
  File jarFile=createPluginJar(TestPlugin.class,new File(tmpDir,"String_Node_Str"),manifest);
  Set<ArtifactRange> parents=ImmutableSet.of(new ArtifactRange(APP_ARTIFACT_ID.getNamespace(),APP_ARTIFACT_ID.getName(),new ArtifactVersion("String_Node_Str"),new ArtifactVersion("String_Node_Str")));
  artifactRepository.addArtifact(artifact1Id,jarFile,parents);
  Map.Entry<ArtifactDescriptor,PluginClass> plugin=artifactRepository.findPlugin(NamespaceId.DEFAULT,APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector());
  Assert.assertNotNull(plugin);
  Assert.assertEquals(new ArtifactVersion("String_Node_Str"),plugin.getKey().getArtifactId().getVersion());
  Assert.assertEquals("String_Node_Str",plugin.getValue().getName());
  Files.copy(Locations.newInputSupplier(plugin.getKey().getLocation()),new File(pluginDir,Artifacts.getFileName(plugin.getKey().getArtifactId())));
  Id.Artifact artifact2Id=Id.Artifact.from(Id.Namespace.DEFAULT,"String_Node_Str","String_Node_Str");
  jarFile=createPluginJar(TestPlugin.class,new File(tmpDir,"String_Node_Str"),manifest);
  artifactRepository.addArtifact(artifact2Id,jarFile,parents);
  plugin=artifactRepository.findPlugin(NamespaceId.DEFAULT,APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector());
  Assert.assertNotNull(plugin);
  Assert.assertEquals(new ArtifactVersion("String_Node_Str"),plugin.getKey().getArtifactId().getVersion());
  Assert.assertEquals("String_Node_Str",plugin.getValue().getName());
  Files.copy(Locations.newInputSupplier(plugin.getKey().getLocation()),new File(pluginDir,Artifacts.getFileName(plugin.getKey().getArtifactId())));
  try (PluginInstantiator instantiator=new PluginInstantiator(cConf,appClassLoader,pluginDir)){
    ClassLoader pluginClassLoader=instantiator.getArtifactClassLoader(plugin.getKey().getArtifactId());
    Class<?> pluginClass=pluginClassLoader.loadClass(TestPlugin2.class.getName());
    plugin=artifactRepository.findPlugin(NamespaceId.DEFAULT,APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector(){
      @Override public Map.Entry<ArtifactId,PluginClass> select(      SortedMap<ArtifactId,PluginClass> plugins){
        return plugins.entrySet().iterator().next();
      }
    }
);
    Assert.assertNotNull(plugin);
    Assert.assertEquals(new ArtifactVersion("String_Node_Str"),plugin.getKey().getArtifactId().getVersion());
    Assert.assertEquals("String_Node_Str",plugin.getValue().getName());
    pluginClassLoader=instantiator.getArtifactClassLoader(plugin.getKey().getArtifactId());
    Assert.assertNotSame(pluginClass,pluginClassLoader.loadClass(TestPlugin2.class.getName()));
    Class<?> cls=pluginClassLoader.loadClass(PluginTestRunnable.class.getName());
    Assert.assertSame(appClassLoader.loadClass(PluginTestRunnable.class.getName()),cls);
    cls=pluginClassLoader.loadClass(Application.class.getName());
    Assert.assertSame(Application.class,cls);
  }
 }

Fixed version (ground truth):
@Test public void testPluginSelector() throws Exception {
  try {
    artifactRepository.findPlugin(NamespaceId.DEFAULT,APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector());
    Assert.fail();
  }
 catch (  PluginNotExistsException e) {
  }
  File pluginDir=DirUtils.createTempDir(tmpDir);
  Id.Artifact artifact1Id=Id.Artifact.from(Id.Namespace.DEFAULT,"String_Node_Str","String_Node_Str");
  Manifest manifest=createManifest(ManifestFields.EXPORT_PACKAGE,TestPlugin.class.getPackage().getName());
  File jarFile=createPluginJar(TestPlugin.class,new File(tmpDir,"String_Node_Str"),manifest);
  Set<ArtifactRange> parents=ImmutableSet.of(new ArtifactRange(APP_ARTIFACT_ID.getNamespace().toEntityId(),APP_ARTIFACT_ID.getName(),new ArtifactVersion("String_Node_Str"),new ArtifactVersion("String_Node_Str")));
  artifactRepository.addArtifact(artifact1Id,jarFile,parents);
  Map.Entry<ArtifactDescriptor,PluginClass> plugin=artifactRepository.findPlugin(NamespaceId.DEFAULT,APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector());
  Assert.assertNotNull(plugin);
  Assert.assertEquals(new ArtifactVersion("String_Node_Str"),plugin.getKey().getArtifactId().getVersion());
  Assert.assertEquals("String_Node_Str",plugin.getValue().getName());
  Files.copy(Locations.newInputSupplier(plugin.getKey().getLocation()),new File(pluginDir,Artifacts.getFileName(plugin.getKey().getArtifactId())));
  Id.Artifact artifact2Id=Id.Artifact.from(Id.Namespace.DEFAULT,"String_Node_Str","String_Node_Str");
  jarFile=createPluginJar(TestPlugin.class,new File(tmpDir,"String_Node_Str"),manifest);
  artifactRepository.addArtifact(artifact2Id,jarFile,parents);
  plugin=artifactRepository.findPlugin(NamespaceId.DEFAULT,APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector());
  Assert.assertNotNull(plugin);
  Assert.assertEquals(new ArtifactVersion("String_Node_Str"),plugin.getKey().getArtifactId().getVersion());
  Assert.assertEquals("String_Node_Str",plugin.getValue().getName());
  Files.copy(Locations.newInputSupplier(plugin.getKey().getLocation()),new File(pluginDir,Artifacts.getFileName(plugin.getKey().getArtifactId())));
  try (PluginInstantiator instantiator=new PluginInstantiator(cConf,appClassLoader,pluginDir)){
    ClassLoader pluginClassLoader=instantiator.getArtifactClassLoader(plugin.getKey().getArtifactId());
    Class<?> pluginClass=pluginClassLoader.loadClass(TestPlugin2.class.getName());
    plugin=artifactRepository.findPlugin(NamespaceId.DEFAULT,APP_ARTIFACT_ID,"String_Node_Str","String_Node_Str",new PluginSelector(){
      @Override public Map.Entry<ArtifactId,PluginClass> select(      SortedMap<ArtifactId,PluginClass> plugins){
        return plugins.entrySet().iterator().next();
      }
    }
);
    Assert.assertNotNull(plugin);
    Assert.assertEquals(new ArtifactVersion("String_Node_Str"),plugin.getKey().getArtifactId().getVersion());
    Assert.assertEquals("String_Node_Str",plugin.getValue().getName());
    pluginClassLoader=instantiator.getArtifactClassLoader(plugin.getKey().getArtifactId());
    Assert.assertNotSame(pluginClass,pluginClassLoader.loadClass(TestPlugin2.class.getName()));
    Class<?> cls=pluginClassLoader.loadClass(PluginTestRunnable.class.getName());
    Assert.assertSame(appClassLoader.loadClass(PluginTestRunnable.class.getName()),cls);
    cls=pluginClassLoader.loadClass(Application.class.getName());
    Assert.assertSame(Application.class,cls);
  }
 }