Program: 20648
Project: 20648
Buggy source:
public Boolean deleteArtifact(Artifact artifact) throws ArchivaRestServiceException {
  String repositoryId=artifact.getContext();
  if (StringUtils.isEmpty(repositoryId)) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  if (!isAuthorizedToDeleteArtifacts(repositoryId)) {
    throw new ArchivaRestServiceException("String_Node_Str",403,null);
  }
  if (artifact == null) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  if (StringUtils.isEmpty(artifact.getGroupId())) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  if (StringUtils.isEmpty(artifact.getArtifactId())) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  boolean snapshotVersion=VersionUtil.isSnapshot(artifact.getVersion()) | VersionUtil.isGenericSnapshot(artifact.getVersion());
  RepositorySession repositorySession=repositorySessionFactory.createSession();
  try {
    Date lastUpdatedTimestamp=Calendar.getInstance().getTime();
    TimeZone timezone=TimeZone.getTimeZone("String_Node_Str");
    DateFormat fmt=new SimpleDateFormat("String_Node_Str");
    fmt.setTimeZone(timezone);
    ManagedRepository repoConfig=managedRepositoryAdmin.getManagedRepository(repositoryId);
    VersionedReference ref=new VersionedReference();
    ref.setArtifactId(artifact.getArtifactId());
    ref.setGroupId(artifact.getGroupId());
    ref.setVersion(artifact.getVersion());
    ManagedRepositoryContent repository=repositoryFactory.getManagedRepositoryContent(repositoryId);
    ArtifactReference artifactReference=new ArtifactReference();
    artifactReference.setArtifactId(artifact.getArtifactId());
    artifactReference.setGroupId(artifact.getGroupId());
    artifactReference.setVersion(artifact.getVersion());
    artifactReference.setClassifier(artifact.getClassifier());
    artifactReference.setType(artifact.getPackaging());
    MetadataRepository metadataRepository=repositorySession.getRepository();
    String path=repository.toMetadataPath(ref);
    if (StringUtils.isNotBlank(artifact.getClassifier())) {
      if (StringUtils.isBlank(artifact.getPackaging())) {
        throw new ArchivaRestServiceException("String_Node_Str",400,null);
      }
      repository.deleteArtifact(artifactReference);
    }
 else {
      int index=path.lastIndexOf('/');
      path=path.substring(0,index);
      File targetPath=new File(repoConfig.getLocation(),path);
      if (!targetPath.exists()) {
        log.warn("String_Node_Str",targetPath);
      }
      if (!snapshotVersion) {
        repository.deleteVersion(ref);
      }
 else {
        Set<ArtifactReference> related=repository.getRelatedArtifacts(artifactReference);
        log.debug("String_Node_Str",related);
        for (        ArtifactReference artifactRef : related) {
          repository.deleteArtifact(artifactRef);
        }
      }
      File metadataFile=getMetadata(targetPath.getAbsolutePath());
      ArchivaRepositoryMetadata metadata=getMetadata(metadataFile);
      updateMetadata(metadata,metadataFile,lastUpdatedTimestamp,artifact);
    }
    Collection<ArtifactMetadata> artifacts=Collections.emptyList();
    if (snapshotVersion) {
      String baseVersion=VersionUtil.getBaseVersion(artifact.getVersion());
      artifacts=metadataRepository.getArtifacts(repositoryId,artifact.getGroupId(),artifact.getArtifactId(),baseVersion);
    }
 else {
      artifacts=metadataRepository.getArtifacts(repositoryId,artifact.getGroupId(),artifact.getArtifactId(),artifact.getVersion());
    }
    log.debug("String_Node_Str",artifacts);
    if (artifacts.isEmpty()) {
      if (!snapshotVersion) {
        Collection<String> projectVersions=metadataRepository.getProjectVersions(repositoryId,artifact.getGroupId(),artifact.getArtifactId());
        if (projectVersions.contains(artifact.getVersion())) {
          log.warn("String_Node_Str");
          metadataRepository.removeProjectVersion(repositoryId,artifact.getGroupId(),artifact.getArtifactId(),artifact.getVersion());
        }
      }
    }
    for (    ArtifactMetadata artifactMetadata : artifacts) {
      if (artifactMetadata.getVersion().equals(artifact.getVersion())) {
        if (StringUtils.isNotBlank(artifact.getClassifier())) {
          if (StringUtils.isBlank(artifact.getPackaging())) {
            throw new ArchivaRestServiceException("String_Node_Str",400,null);
          }
          MavenArtifactFacet mavenArtifactFacet=(MavenArtifactFacet)artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
          if (StringUtils.equals(artifact.getClassifier(),mavenArtifactFacet.getClassifier())) {
            artifactMetadata.removeFacet(MavenArtifactFacet.FACET_ID);
            String groupId=artifact.getGroupId(), artifactId=artifact.getArtifactId(), version=artifact.getVersion();
            MavenArtifactFacet mavenArtifactFacetToCompare=new MavenArtifactFacet();
            mavenArtifactFacetToCompare.setClassifier(artifact.getClassifier());
            metadataRepository.removeArtifact(repositoryId,groupId,artifactId,version,mavenArtifactFacetToCompare);
            metadataRepository.save();
          }
        }
 else {
          if (snapshotVersion) {
            metadataRepository.removeArtifact(artifactMetadata,VersionUtil.getBaseVersion(artifact.getVersion()));
          }
 else {
            metadataRepository.removeArtifact(artifactMetadata.getRepositoryId(),artifactMetadata.getNamespace(),artifactMetadata.getProject(),artifact.getVersion(),artifactMetadata.getId());
          }
        }
        for (        RepositoryListener listener : listeners) {
          listener.deleteArtifact(metadataRepository,repository.getId(),artifactMetadata.getNamespace(),artifactMetadata.getProject(),artifactMetadata.getVersion(),artifactMetadata.getId());
        }
        triggerAuditEvent(repositoryId,path,AuditEvent.REMOVE_FILE);
      }
    }
  }
 catch (  ContentNotFoundException e) {
    throw new ArchivaRestServiceException("String_Node_Str" + e.getMessage(),400,e);
  }
catch (  RepositoryNotFoundException e) {
    throw new ArchivaRestServiceException("String_Node_Str" + e.getMessage(),400,e);
  }
catch (  RepositoryException 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 (  MetadataRepositoryException e) {
    throw new ArchivaRestServiceException("String_Node_Str" + e.getMessage(),500,e);
  }
catch (  RepositoryAdminException 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 deleteArtifact(Artifact artifact) throws ArchivaRestServiceException {
  String repositoryId=artifact.getContext();
  if (StringUtils.isEmpty(repositoryId)) {
    repositoryId=artifact.getRepositoryId();
  }
  if (StringUtils.isEmpty(repositoryId)) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  if (!isAuthorizedToDeleteArtifacts(repositoryId)) {
    throw new ArchivaRestServiceException("String_Node_Str",403,null);
  }
  if (artifact == null) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  if (StringUtils.isEmpty(artifact.getGroupId())) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  if (StringUtils.isEmpty(artifact.getArtifactId())) {
    throw new ArchivaRestServiceException("String_Node_Str",400,null);
  }
  boolean snapshotVersion=VersionUtil.isSnapshot(artifact.getVersion()) | VersionUtil.isGenericSnapshot(artifact.getVersion());
  RepositorySession repositorySession=repositorySessionFactory.createSession();
  try {
    Date lastUpdatedTimestamp=Calendar.getInstance().getTime();
    TimeZone timezone=TimeZone.getTimeZone("String_Node_Str");
    DateFormat fmt=new SimpleDateFormat("String_Node_Str");
    fmt.setTimeZone(timezone);
    ManagedRepository repoConfig=managedRepositoryAdmin.getManagedRepository(repositoryId);
    VersionedReference ref=new VersionedReference();
    ref.setArtifactId(artifact.getArtifactId());
    ref.setGroupId(artifact.getGroupId());
    ref.setVersion(artifact.getVersion());
    ManagedRepositoryContent repository=repositoryFactory.getManagedRepositoryContent(repositoryId);
    ArtifactReference artifactReference=new ArtifactReference();
    artifactReference.setArtifactId(artifact.getArtifactId());
    artifactReference.setGroupId(artifact.getGroupId());
    artifactReference.setVersion(artifact.getVersion());
    artifactReference.setClassifier(artifact.getClassifier());
    artifactReference.setType(artifact.getPackaging());
    MetadataRepository metadataRepository=repositorySession.getRepository();
    String path=repository.toMetadataPath(ref);
    if (StringUtils.isNotBlank(artifact.getClassifier())) {
      if (StringUtils.isBlank(artifact.getPackaging())) {
        throw new ArchivaRestServiceException("String_Node_Str",400,null);
      }
      repository.deleteArtifact(artifactReference);
    }
 else {
      int index=path.lastIndexOf('/');
      path=path.substring(0,index);
      File targetPath=new File(repoConfig.getLocation(),path);
      if (!targetPath.exists()) {
        log.warn("String_Node_Str",targetPath);
      }
      if (!snapshotVersion) {
        repository.deleteVersion(ref);
      }
 else {
        Set<ArtifactReference> related=repository.getRelatedArtifacts(artifactReference);
        log.debug("String_Node_Str",related);
        for (        ArtifactReference artifactRef : related) {
          repository.deleteArtifact(artifactRef);
        }
      }
      File metadataFile=getMetadata(targetPath.getAbsolutePath());
      ArchivaRepositoryMetadata metadata=getMetadata(metadataFile);
      updateMetadata(metadata,metadataFile,lastUpdatedTimestamp,artifact);
    }
    Collection<ArtifactMetadata> artifacts=Collections.emptyList();
    if (snapshotVersion) {
      String baseVersion=VersionUtil.getBaseVersion(artifact.getVersion());
      artifacts=metadataRepository.getArtifacts(repositoryId,artifact.getGroupId(),artifact.getArtifactId(),baseVersion);
    }
 else {
      artifacts=metadataRepository.getArtifacts(repositoryId,artifact.getGroupId(),artifact.getArtifactId(),artifact.getVersion());
    }
    log.debug("String_Node_Str",artifacts);
    if (artifacts.isEmpty()) {
      if (!snapshotVersion) {
        Collection<String> projectVersions=metadataRepository.getProjectVersions(repositoryId,artifact.getGroupId(),artifact.getArtifactId());
        if (projectVersions.contains(artifact.getVersion())) {
          log.warn("String_Node_Str");
          metadataRepository.removeProjectVersion(repositoryId,artifact.getGroupId(),artifact.getArtifactId(),artifact.getVersion());
        }
      }
    }
    for (    ArtifactMetadata artifactMetadata : artifacts) {
      if (artifactMetadata.getVersion().equals(artifact.getVersion())) {
        if (StringUtils.isNotBlank(artifact.getClassifier())) {
          if (StringUtils.isBlank(artifact.getPackaging())) {
            throw new ArchivaRestServiceException("String_Node_Str",400,null);
          }
          MavenArtifactFacet mavenArtifactFacet=(MavenArtifactFacet)artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
          if (StringUtils.equals(artifact.getClassifier(),mavenArtifactFacet.getClassifier())) {
            artifactMetadata.removeFacet(MavenArtifactFacet.FACET_ID);
            String groupId=artifact.getGroupId(), artifactId=artifact.getArtifactId(), version=artifact.getVersion();
            MavenArtifactFacet mavenArtifactFacetToCompare=new MavenArtifactFacet();
            mavenArtifactFacetToCompare.setClassifier(artifact.getClassifier());
            metadataRepository.removeArtifact(repositoryId,groupId,artifactId,version,mavenArtifactFacetToCompare);
            metadataRepository.save();
          }
        }
 else {
          if (snapshotVersion) {
            metadataRepository.removeArtifact(artifactMetadata,VersionUtil.getBaseVersion(artifact.getVersion()));
          }
 else {
            metadataRepository.removeArtifact(artifactMetadata.getRepositoryId(),artifactMetadata.getNamespace(),artifactMetadata.getProject(),artifact.getVersion(),artifactMetadata.getId());
          }
        }
        for (        RepositoryListener listener : listeners) {
          listener.deleteArtifact(metadataRepository,repository.getId(),artifactMetadata.getNamespace(),artifactMetadata.getProject(),artifactMetadata.getVersion(),artifactMetadata.getId());
        }
        triggerAuditEvent(repositoryId,path,AuditEvent.REMOVE_FILE);
      }
    }
  }
 catch (  ContentNotFoundException e) {
    throw new ArchivaRestServiceException("String_Node_Str" + e.getMessage(),400,e);
  }
catch (  RepositoryNotFoundException e) {
    throw new ArchivaRestServiceException("String_Node_Str" + e.getMessage(),400,e);
  }
catch (  RepositoryException 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 (  MetadataRepositoryException e) {
    throw new ArchivaRestServiceException("String_Node_Str" + e.getMessage(),500,e);
  }
catch (  RepositoryAdminException e) {
    throw new ArchivaRestServiceException("String_Node_Str" + e.getMessage(),500,e);
  }
 finally {
    repositorySession.save();
    repositorySession.close();
  }
  return Boolean.TRUE;
}