Program: 167813
Project: 167813
Buggy source:
public void execute(OperationContext context,ModelNode operation) throws OperationFailedException {
  for (  AttributeDefinition def : DeploymentAttributes.FULL_REPLACE_DEPLOYMENT_ATTRIBUTES.values()) {
    def.validateOperation(operation);
  }
  String name=DeploymentAttributes.FULL_REPLACE_DEPLOYMENT_ATTRIBUTES.get(NAME).resolveModelAttribute(context,operation).asString();
  final PathAddress address=PathAddress.EMPTY_ADDRESS.append(PathElement.pathElement(DEPLOYMENT,name));
  final Resource root=context.readResource(PathAddress.EMPTY_ADDRESS);
  boolean exists=root.hasChild(PathElement.pathElement(DEPLOYMENT,name));
  if (!exists) {
    ServerMessages.MESSAGES.noSuchDeployment(name);
  }
  final ModelNode replaceNode=context.readResourceForUpdate(address).getModel();
  final String replacedRuntimeName=RUNTIME_NAME.resolveModelAttribute(context,replaceNode).asString();
  final String runtimeName=operation.hasDefined(RUNTIME_NAME.getName()) ? operation.get(RUNTIME_NAME.getName()).asString() : name;
  final ModelNode content=operation.require(CONTENT).clone();
  final DeploymentHandlerUtil.ContentItem contentItem;
  ModelNode contentItemNode=content.require(0);
  byte[] originalHash=contentItemNode.hasDefined(CONTENT_HASH.getName()) ? CONTENT_HASH.resolveModelAttribute(context,contentItemNode).asBytes() : null;
  if (contentItemNode.hasDefined(CONTENT_HASH.getName())) {
    byte[] hash=CONTENT_HASH.resolveModelAttribute(context,contentItemNode).asBytes();
    contentItem=addFromHash(hash);
  }
 else   if (hasValidContentAdditionParameterDefined(contentItemNode)) {
    contentItem=addFromContentAdditionParameter(context,contentItemNode);
    contentItemNode=new ModelNode();
    contentItemNode.get(CONTENT_HASH.getName()).set(contentItem.getHash());
    content.clear();
    content.add(contentItemNode);
  }
 else {
    contentItem=addUnmanaged(context,contentItemNode);
  }
  final ModelNode deployNode=context.readResourceForUpdate(address).getModel();
  removeContentAdditions(deployNode.require(CONTENT));
  deployNode.get(NAME).set(name);
  deployNode.get(RUNTIME_NAME.getName()).set(runtimeName);
  deployNode.get(CONTENT).set(content);
  ENABLED.validateAndSet(deployNode,replaceNode);
  if (ENABLED.resolveModelAttribute(context,replaceNode).asBoolean()) {
    DeploymentHandlerUtil.replace(context,replaceNode,runtimeName,name,replacedRuntimeName,vaultReader,contentItem);
  }
  if (context.completeStep() == ResultAction.KEEP) {
    if (originalHash != null) {
      final ModelNode contentNode=replaceNode.get(CONTENT).get(0);
      if (contentNode.hasDefined(CONTENT_HASH.getName())) {
        byte[] newHash=CONTENT_HASH.resolveModelAttribute(context,contentNode).asBytes();
        if (!Arrays.equals(originalHash,newHash)) {
          contentRepository.removeContent(originalHash);
        }
      }
    }
  }
 else {
    final ModelNode contentNode=replaceNode.get(CONTENT).get(0);
    if (contentNode.hasDefined(CONTENT_HASH.getName())) {
      byte[] newHash=CONTENT_HASH.resolveModelAttribute(context,contentNode).asBytes();
      contentRepository.removeContent(newHash);
    }
  }
}

Fixed version (ground truth):
public void execute(OperationContext context,ModelNode operation) throws OperationFailedException {
  for (  AttributeDefinition def : DeploymentAttributes.FULL_REPLACE_DEPLOYMENT_ATTRIBUTES.values()) {
    def.validateOperation(operation);
  }
  String name=DeploymentAttributes.FULL_REPLACE_DEPLOYMENT_ATTRIBUTES.get(NAME).resolveModelAttribute(context,operation).asString();
  final PathAddress address=PathAddress.EMPTY_ADDRESS.append(PathElement.pathElement(DEPLOYMENT,name));
  final Resource root=context.readResource(PathAddress.EMPTY_ADDRESS);
  boolean exists=root.hasChild(PathElement.pathElement(DEPLOYMENT,name));
  if (!exists) {
    ServerMessages.MESSAGES.noSuchDeployment(name);
  }
  final ModelNode replaceNode=context.readResourceForUpdate(address).getModel();
  final String replacedRuntimeName=RUNTIME_NAME.resolveModelAttribute(context,replaceNode).asString();
  final String runtimeName=operation.hasDefined(RUNTIME_NAME.getName()) ? operation.get(RUNTIME_NAME.getName()).asString() : name;
  final ModelNode content=operation.require(CONTENT).clone();
  final DeploymentHandlerUtil.ContentItem contentItem;
  ModelNode contentItemNode=content.require(0);
  byte[] originalHash=replaceNode.get(CONTENT).get(0).hasDefined(CONTENT_HASH.getName()) ? CONTENT_HASH.resolveModelAttribute(context,replaceNode.get(CONTENT).get(0)).asBytes() : null;
  if (contentItemNode.hasDefined(CONTENT_HASH.getName())) {
    byte[] hash=CONTENT_HASH.resolveModelAttribute(context,contentItemNode).asBytes();
    contentItem=addFromHash(hash);
  }
 else   if (hasValidContentAdditionParameterDefined(contentItemNode)) {
    contentItem=addFromContentAdditionParameter(context,contentItemNode);
    contentItemNode=new ModelNode();
    contentItemNode.get(CONTENT_HASH.getName()).set(contentItem.getHash());
    content.clear();
    content.add(contentItemNode);
  }
 else {
    contentItem=addUnmanaged(context,contentItemNode);
  }
  final ModelNode deployNode=context.readResourceForUpdate(address).getModel();
  removeContentAdditions(deployNode.require(CONTENT));
  deployNode.get(NAME).set(name);
  deployNode.get(RUNTIME_NAME.getName()).set(runtimeName);
  deployNode.get(CONTENT).set(content);
  ENABLED.validateAndSet(deployNode,replaceNode);
  if (ENABLED.resolveModelAttribute(context,replaceNode).asBoolean()) {
    DeploymentHandlerUtil.replace(context,replaceNode,runtimeName,name,replacedRuntimeName,vaultReader,contentItem);
  }
  if (context.completeStep() == ResultAction.KEEP) {
    if (originalHash != null) {
      final ModelNode contentNode=replaceNode.get(CONTENT).get(0);
      if (contentNode.hasDefined(CONTENT_HASH.getName())) {
        byte[] newHash=CONTENT_HASH.resolveModelAttribute(context,contentNode).asBytes();
        if (!Arrays.equals(originalHash,newHash)) {
          contentRepository.removeContent(originalHash);
        }
      }
    }
  }
 else {
    final ModelNode contentNode=replaceNode.get(CONTENT).get(0);
    if (contentNode.hasDefined(CONTENT_HASH.getName())) {
      byte[] newHash=CONTENT_HASH.resolveModelAttribute(context,contentNode).asBytes();
      contentRepository.removeContent(newHash);
    }
  }
}