Buggy code:
class PatchXmlUtils implements XMLStreamConstants { private static final String PATH_DELIMITER = "//" ; enum Element { ADDED ( "added" ) , BUNDLES ( "bundles" ) , DESCRIPTION ( "description" ) , IDENTITY ( "identity" ) , REQUIRES ( "requires" ) , MISC_FILES ( "misc-files" ) , MODULES ( "modules" ) , NO_UPGRADE ( "no-upgrade" ) , ONE_OFF ( "one-off" ) , PATCH ( "patch" ) , PATCH_ELEMENT ( "element" ) , REMOVED ( "removed" ) , UPDATED ( "updated" ) , UPGRADE ( "upgrade" ) , UNKNOWN ( null ) ; public final String name ; Element ( String name ) { } static Map < String , PatchXmlUtils . Element > elements = new HashMap < String , PatchXmlUtils . Element > ( ) ; static PatchXmlUtils . Element forName ( String name ) { } } enum Attribute { ADD_ON ( "add-on" ) , DIRECTORY ( "directory" ) , EXISTING_PATH ( "existing-path" ) , HASH ( "hash" ) , ID ( "id" ) , IN_RUNTIME_USE ( "in-runtime-use" ) , NAME ( "name" ) , NEW_HASH ( "new-hash" ) , PATH ( "path" ) , SLOT ( "slot" ) , TO_VERSION ( "to-version" ) , VERSION ( "version" ) , UNKNOWN ( null ) ; private final String name ; Attribute ( String name ) { } static Map < String , PatchXmlUtils . Attribute > attributes = new HashMap < String , PatchXmlUtils . Attribute > ( ) ; static PatchXmlUtils . Attribute forName ( String name ) { } } protected static void writePatch ( final XMLExtendedStreamWriter writer , final Patch patch ) throws XMLStreamException { } protected static void writeContentModifications ( final XMLExtendedStreamWriter writer , final Collection < ContentModification > modifications ) throws XMLStreamException { } protected void doReadElement ( final XMLExtendedStreamReader reader , final PatchBuilder builder ) throws XMLStreamException { } protected void handleRootElement ( final String localName , final XMLExtendedStreamReader reader , final PatchBuilder builder ) throws XMLStreamException { } static void parseElement ( final XMLExtendedStreamReader reader , final PatchBuilder builder ) throws XMLStreamException { } static void parseElementProvider ( final XMLExtendedStreamReader reader , PatchElementImpl patchElement , Patch . PatchType patchType ) throws XMLStreamException { } static void parseIdentity ( final XMLExtendedStreamReader reader , final PatchBuilder builder , final Patch . PatchType patchType ) throws XMLStreamException { } static void parseIncluded ( final XMLExtendedStreamReader reader , final RequiresCallback includes ) throws XMLStreamException { } static void parseModules ( final XMLExtendedStreamReader reader , final Collection < ContentModification > modifications ) throws XMLStreamException { } static void parseMiscFiles ( final XMLExtendedStreamReader reader , final Collection < ContentModification > modifications ) throws XMLStreamException { } static void parseBundles ( final XMLExtendedStreamReader reader , final Collection < ContentModification > modifications ) throws XMLStreamException { } static ContentModification parseBundleModification ( final XMLExtendedStreamReader reader , final ModificationType type ) throws XMLStreamException { } static ContentModification parseModuleModification ( final XMLExtendedStreamReader reader , final ModificationType type ) throws XMLStreamException { } static ContentModification parseSlottedItem ( final XMLExtendedStreamReader reader , ModificationType modificationType , ContentType contentType ) throws XMLStreamException { } static ContentModification parseMiscModification ( final XMLExtendedStreamReader reader , ModificationType type ) throws XMLStreamException { } protected static void writeAppliesToVersions ( XMLExtendedStreamWriter writer , List < String > appliesTo ) throws XMLStreamException { } protected static void writeSlottedItems ( final XMLExtendedStreamWriter writer , final PatchXmlUtils . Element element , final List < ContentModification > modifications ) throws XMLStreamException { } protected static void writeSlottedItem ( final XMLExtendedStreamWriter writer , PatchXmlUtils . Element element , ContentModification modification ) throws XMLStreamException { writer . writeEmptyElement ( element . name ) ; final ModuleItem item = ( ( ModuleItem ) ( modification . getItem ( ) ) ) ; final ModificationType type = modification . getType ( ) ; writer . writeAttribute ( PatchXmlUtils . Attribute . NAME . name , item . getName ( ) ) ; if ( ! ( ModuleItem . MAIN_SLOT . equals ( item . getSlot ( ) ) ) ) { writer . writeAttribute ( PatchXmlUtils . Attribute . SLOT . name , item . getSlot ( ) ) ; } byte [ ] hash = item . getContentHash ( ) ; <START_BUG> if ( ( hash . length ) > 0 ) { <END_BUG> writer . writeAttribute ( PatchXmlUtils . Attribute . HASH . name , HashUtils . bytesToHexString ( hash ) ) ; } if ( type == ( ModificationType . REMOVE ) ) { final byte [ ] existingHash = modification . getTargetHash ( ) ; if ( ( existingHash . length ) > 0 ) { writer . writeAttribute ( PatchXmlUtils . Attribute . HASH . name , HashUtils . bytesToHexString ( existingHash ) ) ; } } else if ( type == ( ModificationType . MODIFY ) ) { final byte [ ] existingHash = modification . getTargetHash ( ) ; if ( ( existingHash . length ) > 0 ) { writer . writeAttribute ( PatchXmlUtils . Attribute . NEW_HASH . name , HashUtils . bytesToHexString ( existingHash ) ) ; } } } protected static void writeMiscItems ( final XMLExtendedStreamWriter writer , final PatchXmlUtils . Element element , final List < ContentModification > modifications ) throws XMLStreamException { } protected static void writeMiscItem ( final XMLExtendedStreamWriter writer , final PatchXmlUtils . Element element , final ContentModification modification ) throws XMLStreamException { } }

Fix:
if ( ( ( hash . length ) > 0 ) && ( type != ( ModificationType . REMOVE ) ) ) {