Program: 20649
Project: 20649
Buggy source:
public Boolean removeProjectVersion(String repositoryId,String namespace,String projectId,String version) throws ArchivaRestServiceException {
  if (!VersionUtil.isGenericSnapshot(version)) {
    Artifact artifact=new Artifact(namespace,projectId,version);
    return deleteArtifact(artifact);
  }
  if (StringUtils.isEmpty(repositoryId)) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  if (!isAuthorizedToDeleteArtifacts(repositoryId)) {
    throw new ArchivaRestServiceException("String_Node_Str",403,null);
  }
  if (StringUtils.isEmpty(namespace)) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  if (StringUtils.isEmpty(projectId)) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  if (StringUtils.isEmpty(version)) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  RepositorySession repositorySession=repositorySessionFactory.createSession();
  try {
    ManagedRepositoryContent repository=repositoryFactory.getManagedRepositoryContent(repositoryId);
    VersionedReference ref=new VersionedReference();
    ref.setArtifactId(projectId);
    ref.setGroupId(namespace);
    ref.setVersion(version);
    repository.deleteVersion(ref);
    ArtifactReference artifactReference=new ArtifactReference();
    artifactReference.setGroupId(namespace);
    artifactReference.setArtifactId(projectId);
    artifactReference.setVersion(version);
    MetadataRepository metadataRepository=repositorySession.getRepository();
    Set<ArtifactReference> related=repository.getRelatedArtifacts(artifactReference);
    log.debug("String_Node_Str",related);
    for (    ArtifactReference artifactRef : related) {
      repository.deleteArtifact(artifactRef);
    }
    Collection<ArtifactMetadata> artifacts=metadataRepository.getArtifacts(repositoryId,namespace,projectId,version);
    for (    ArtifactMetadata artifactMetadata : artifacts) {
      metadataRepository.removeArtifact(artifactMetadata,version);
    }
    metadataRepository.removeProjectVersion(repositoryId,namespace,projectId,version);
  }
 catch (  MetadataRepositoryException e) {
    throw new ArchivaRestServiceException("String_Node_Str" + e.getMessage(),500,e);
  }
catch (  MetadataResolutionException e) {
    throw new ArchivaRestServiceException("String_Node_Str" + e.getMessage(),500,e);
  }
catch (  RepositoryException e) {
    throw new ArchivaRestServiceException("String_Node_Str" + e.getMessage(),500,e);
  }
 finally {
    repositorySession.save();
    repositorySession.close();
  }
  return Boolean.TRUE;
}

Fixed version (ground truth):
public Boolean removeProjectVersion(String repositoryId,String namespace,String projectId,String version) throws ArchivaRestServiceException {
  if (!VersionUtil.isGenericSnapshot(version)) {
    Artifact artifact=new Artifact(namespace,projectId,version);
    artifact.setRepositoryId(repositoryId);
    return deleteArtifact(artifact);
  }
  if (StringUtils.isEmpty(repositoryId)) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  if (!isAuthorizedToDeleteArtifacts(repositoryId)) {
    throw new ArchivaRestServiceException("String_Node_Str",403,null);
  }
  if (StringUtils.isEmpty(namespace)) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  if (StringUtils.isEmpty(projectId)) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  if (StringUtils.isEmpty(version)) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  RepositorySession repositorySession=repositorySessionFactory.createSession();
  try {
    ManagedRepositoryContent repository=repositoryFactory.getManagedRepositoryContent(repositoryId);
    VersionedReference ref=new VersionedReference();
    ref.setArtifactId(projectId);
    ref.setGroupId(namespace);
    ref.setVersion(version);
    repository.deleteVersion(ref);
    ArtifactReference artifactReference=new ArtifactReference();
    artifactReference.setGroupId(namespace);
    artifactReference.setArtifactId(projectId);
    artifactReference.setVersion(version);
    MetadataRepository metadataRepository=repositorySession.getRepository();
    Set<ArtifactReference> related=repository.getRelatedArtifacts(artifactReference);
    log.debug("String_Node_Str",related);
    for (    ArtifactReference artifactRef : related) {
      repository.deleteArtifact(artifactRef);
    }
    Collection<ArtifactMetadata> artifacts=metadataRepository.getArtifacts(repositoryId,namespace,projectId,version);
    for (    ArtifactMetadata artifactMetadata : artifacts) {
      metadataRepository.removeArtifact(artifactMetadata,version);
    }
    metadataRepository.removeProjectVersion(repositoryId,namespace,projectId,version);
  }
 catch (  MetadataRepositoryException e) {
    throw new ArchivaRestServiceException("String_Node_Str" + e.getMessage(),500,e);
  }
catch (  MetadataResolutionException e) {
    throw new ArchivaRestServiceException("String_Node_Str" + e.getMessage(),500,e);
  }
catch (  RepositoryException e) {
    throw new ArchivaRestServiceException("String_Node_Str" + e.getMessage(),500,e);
  }
 finally {
    repositorySession.save();
    repositorySession.close();
  }
  return Boolean.TRUE;
}