Buggy code:
public class DeploymentFullReplaceHandler implements OperationStepHandler { public static final String OPERATION_NAME = FULL_REPLACE_DEPLOYMENT ; protected final ContentRepository contentRepository ; private final AbstractVaultReader vaultReader ; protected DeploymentFullReplaceHandler ( final ContentRepository contentRepository , final AbstractVaultReader vaultReader ) { } public static DeploymentFullReplaceHandler create ( final ContentRepository contentRepository , final AbstractVaultReader vaultReader ) { } public void execute ( OperationContext context , ModelNode operation ) throws OperationFailedException { for ( AttributeDefinition def : FULL_REPLACE_DEPLOYMENT_ATTRIBUTES . values ( ) ) { def . validateOperation ( operation ) ; } String name = FULL_REPLACE_DEPLOYMENT_ATTRIBUTES . get ( NAME ) . resolveModelAttribute ( context , operation ) . asString ( ) ; final PathAddress address = EMPTY_ADDRESS . append ( PathElement . pathElement ( DEPLOYMENT , name ) ) ; final Resource root = context . readResource ( EMPTY_ADDRESS ) ; boolean exists = root . hasChild ( PathElement . pathElement ( DEPLOYMENT , name ) ) ; if ( ! exists ) { 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 ) ; <START_BUG> byte [ ] originalHash = ( contentItemNode . hasDefined ( CONTENT_HASH . getName ( ) ) ) ? CONTENT_HASH . resolveModelAttribute ( context , contentItemNode ) . asBytes ( ) : null ; <END_BUG> if ( contentItemNode . hasDefined ( CONTENT_HASH . getName ( ) ) ) { byte [ ] hash = CONTENT_HASH . resolveModelAttribute ( context , contentItemNode ) . asBytes ( ) ; contentItem = addFromHash ( hash ) ; } else if ( DeploymentHandlerUtils . 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 ( ) ; DeploymentFullReplaceHandler . 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 ) ; } } } private static void removeAttributes ( final ModelNode node , final Iterable < String > attributeNames ) { } private static void removeContentAdditions ( final ModelNode content ) { } ContentItem addFromHash ( byte [ ] hash ) throws OperationFailedException { } ContentItem addFromContentAdditionParameter ( OperationContext context , ModelNode contentItemNode ) throws OperationFailedException { } ContentItem addUnmanaged ( OperationContext context , ModelNode contentItemNode ) throws OperationFailedException { } }

Fix:
byte [ ] originalHash = ( replaceNode . get ( CONTENT ) . get ( 0 ) . hasDefined ( CONTENT_HASH . getName ( ) ) ) ? CONTENT_HASH . resolveModelAttribute ( context , replaceNode . get ( CONTENT ) . get ( 0 ) ) . asBytes ( ) : null ;