Program: 6485
Project: 6485
Buggy source:
/** 
 * Get all plugin classes of the given type and name that extend the given parent artifact. Results are returned as a map from plugin artifact to plugins in that artifact.
 * @param parentArtifactId the id of the artifact to find plugins for
 * @param type the type of plugin to look for
 * @param name the name of the plugin to look for
 * @return an unmodifiable map of plugin artifact to plugin classes of the given type and name, accessible by thegiven artifact. The map will never be null, and will never be empty.
 * @throws PluginNotExistsException if no plugin with the given type and name exists in the namespace
 * @throws IOException if there was an exception reading metadata from the metastore
 */
public SortedMap<ArtifactDescriptor,PluginClass> getPluginClasses(final Id.Artifact parentArtifactId,final String type,final String name) throws IOException, PluginNotExistsException {
  SortedMap<ArtifactDescriptor,PluginClass> plugins=metaTable.executeUnchecked(new TransactionExecutor.Function<DatasetContext<Table>,SortedMap<ArtifactDescriptor,PluginClass>>(){
    @Override public SortedMap<ArtifactDescriptor,PluginClass> apply(    DatasetContext<Table> context) throws Exception {
      SortedMap<ArtifactDescriptor,PluginClass> result=Maps.newTreeMap();
      PluginKey pluginKey=new PluginKey(parentArtifactId.getNamespace(),parentArtifactId.getName(),type,name);
      Row row=context.get().get(pluginKey.getRowKey());
      if (!row.isEmpty()) {
        for (        Map.Entry<byte[],byte[]> column : row.getColumns().entrySet()) {
          ArtifactColumn artifactColumn=ArtifactColumn.parse(column.getKey());
          PluginData pluginData=gson.fromJson(Bytes.toString(column.getValue()),PluginData.class);
          if (pluginData.usableBy.versionIsInRange(parentArtifactId.getVersion())) {
            ArtifactDescriptor artifactInfo=new ArtifactDescriptor(artifactColumn.artifactId.toArtifactId(),locationFactory.create(pluginData.artifactLocationURI));
            result.put(artifactInfo,pluginData.pluginClass);
          }
        }
      }
      return result;
    }
  }
);
  if (plugins.isEmpty()) {
    throw new PluginNotExistsException(parentArtifactId.getNamespace(),type,name);
  }
  return Collections.unmodifiableSortedMap(plugins);
}

Fixed version (ground truth):
/** 
 * Get all plugin classes of the given type and name that extend the given parent artifact. Results are returned as a map from plugin artifact to plugins in that artifact.
 * @param parentArtifactId the id of the artifact to find plugins for
 * @param type the type of plugin to look for
 * @param name the name of the plugin to look for
 * @return an unmodifiable map of plugin artifact to plugin classes of the given type and name, accessible by thegiven artifact. The map will never be null, and will never be empty.
 * @throws PluginNotExistsException if no plugin with the given type and name exists in the namespace
 * @throws IOException if there was an exception reading metadata from the metastore
 */
public SortedMap<ArtifactDescriptor,PluginClass> getPluginClasses(final Id.Artifact parentArtifactId,final String type,final String name) throws IOException, ArtifactNotFoundException, PluginNotExistsException {
  SortedMap<ArtifactDescriptor,PluginClass> plugins=metaTable.executeUnchecked(new TransactionExecutor.Function<DatasetContext<Table>,SortedMap<ArtifactDescriptor,PluginClass>>(){
    @Override public SortedMap<ArtifactDescriptor,PluginClass> apply(    DatasetContext<Table> context) throws Exception {
      Table table=context.get();
      SortedMap<ArtifactDescriptor,PluginClass> result=new TreeMap<>();
      ArtifactCell parentCell=new ArtifactCell(parentArtifactId);
      byte[] parentDataBytes=table.get(parentCell.rowkey,parentCell.column);
      if (parentDataBytes == null) {
        return null;
      }
      ArtifactData parentData=gson.fromJson(Bytes.toString(parentDataBytes),ArtifactData.class);
      Set<PluginClass> parentPlugins=parentData.meta.getClasses().getPlugins();
      for (      PluginClass pluginClass : parentPlugins) {
        if (pluginClass.getName().equals(name) && pluginClass.getType().equals(type)) {
          ArtifactDescriptor parentDescriptor=new ArtifactDescriptor(parentArtifactId.toArtifactId(),locationFactory.create(parentData.locationURI));
          result.put(parentDescriptor,pluginClass);
          break;
        }
      }
      PluginKey pluginKey=new PluginKey(parentArtifactId.getNamespace(),parentArtifactId.getName(),type,name);
      Row row=context.get().get(pluginKey.getRowKey());
      if (!row.isEmpty()) {
        for (        Map.Entry<byte[],byte[]> column : row.getColumns().entrySet()) {
          ArtifactColumn artifactColumn=ArtifactColumn.parse(column.getKey());
          PluginData pluginData=gson.fromJson(Bytes.toString(column.getValue()),PluginData.class);
          if (pluginData.usableBy.versionIsInRange(parentArtifactId.getVersion())) {
            ArtifactDescriptor artifactInfo=new ArtifactDescriptor(artifactColumn.artifactId.toArtifactId(),locationFactory.create(pluginData.artifactLocationURI));
            result.put(artifactInfo,pluginData.pluginClass);
          }
        }
      }
      return result;
    }
  }
);
  if (plugins == null) {
    throw new ArtifactNotFoundException(parentArtifactId);
  }
  if (plugins.isEmpty()) {
    throw new PluginNotExistsException(parentArtifactId.getNamespace(),type,name);
  }
  return Collections.unmodifiableSortedMap(plugins);
}