Buggy code:
} protected static void writePatch ( final XMLExtendedStreamWriter writer , final Patch patch ) throws XMLStreamException { writer . writeAttribute ( PatchXmlUtils . Attribute . ID . name , patch . getPatchId ( ) ) ; String description = patch . getDescription ( ) ; if ( description != null ) { writer . writeStartElement ( PatchXmlUtils . Element . DESCRIPTION . name ) ; writer . writeCharacters ( description ) ; writer . writeEndElement ( ) ; } final Identity identity = patch . getIdentity ( ) ; final Patch . PatchType type = identity . getPatchType ( ) ; if ( type == ( PatchType . UPGRADE ) ) { writer . writeStartElement ( PatchXmlUtils . Element . UPGRADE . name ) ; } else if ( type == ( PatchType . CUMULATIVE ) ) { writer . writeStartElement ( PatchXmlUtils . Element . NO_UPGRADE . name ) ; } else { writer . writeStartElement ( PatchXmlUtils . Element . ONE_OFF . name ) ; } writer . writeAttribute ( PatchXmlUtils . Attribute . NAME . name , identity . getName ( ) ) ; writer . writeAttribute ( PatchXmlUtils . Attribute . VERSION . name , identity . getVersion ( ) ) ; if ( type == ( PatchType . UPGRADE ) ) { final Identity . IdentityUpgrade upgrade = identity . forType ( UPGRADE , IdentityUpgrade . class ) ; writer . writeAttribute ( PatchXmlUtils . Attribute . TO_VERSION . name , upgrade . getResultingVersion ( ) ) ; } else if ( type == ( PatchType . ONE_OFF ) ) { final Identity . IdentityOneOffPatch oneOffPatch = identity . forType ( ONE_OFF , IdentityOneOffPatch . class ) ; writer . writeAttribute ( PatchXmlUtils . Attribute . CUMULATIVE_PATCH_ID . name , oneOffPatch . getCumulativePatchId ( ) ) ; } if ( ! ( identity . getRequires ( ) . isEmpty ( ) ) ) { writer . writeStartElement ( PatchXmlUtils . Element . REQUIRES . name ) ; for ( String patchId : identity . getRequires ( ) ) { writer . writeStartElement ( PatchXmlUtils . Element . PATCH . name ) ; writer . writeAttribute ( PatchXmlUtils . Attribute . ID . name , patchId ) ; writer . writeEndElement ( ) ; } writer . writeEndElement ( ) ; } writer . writeEndElement ( ) ; final List < PatchElement > elements = patch . getElements ( ) ; for ( PatchElement element : elements ) { final PatchXmlUtils . Element startElement = ( element . getProvider ( ) . isAddOn ( ) ) ? PatchXmlUtils . Element . ADD_ON : PatchXmlUtils . Element . LAYER ; writer . writeStartElement ( startElement . name ) ; writer . writeAttribute ( PatchXmlUtils . Attribute . ID . name , element . getId ( ) ) ; if ( ( element . getDescription ( ) ) != null ) { writer . writeStartElement ( PatchXmlUtils . Element . DESCRIPTION . name ) ; writer . writeCharacters ( element . getDescription ( ) ) ; writer . writeEndElement ( ) ; } final PatchElementProvider provider = element . getProvider ( ) ; if ( provider == null ) { throw new XMLStreamException ( ( "Provider<seq2seq4repair_space>is<seq2seq4repair_space>missing<seq2seq4repair_space>for<seq2seq4repair_space>patch<seq2seq4repair_space>element<seq2seq4repair_space>" + ( element . getId ( ) ) ) ) ; } final Patch . PatchType elementPatchType = provider . getPatchType ( ) ; if ( elementPatchType == ( PatchType . UPGRADE ) ) { writer . writeStartElement ( PatchXmlUtils . Element . UPGRADE . name ) ; } else if ( elementPatchType == ( PatchType . CUMULATIVE ) ) { writer . writeStartElement ( PatchXmlUtils . Element . NO_UPGRADE . name ) ; } else { writer . writeStartElement ( PatchXmlUtils . Element . ONE_OFF . name ) ; } writer . writeAttribute ( PatchXmlUtils . Attribute . NAME . name , provider . getName ( ) ) ; <START_BUG> if ( type == ( PatchType . ONE_OFF ) ) { <END_BUG> final PatchElementProvider . OneOffPatchTarget oneOffPatch = provider . forType ( ONE_OFF , OneOffPatchTarget . class ) ; writer . writeAttribute ( PatchXmlUtils . Attribute . CUMULATIVE_PATCH_ID . name , oneOffPatch . getCumulativePatchId ( ) ) ; } if ( ! ( provider . getRequires ( ) . isEmpty ( ) ) ) { writer . writeStartElement ( PatchXmlUtils . Element . REQUIRES . name ) ; for ( String elementId : provider . getRequires ( ) ) { writer . writeStartElement ( PatchXmlUtils . Element . PATCH . name ) ; writer . writeAttribute ( PatchXmlUtils . Attribute . ID . name , elementId ) ; writer . writeEndElement ( ) ; } writer . writeEndElement ( ) ; } writer . writeEndElement ( ) ; PatchXmlUtils . writeContentModifications ( writer , element . getModifications ( ) ) ; writer . writeEndElement ( ) ; } PatchXmlUtils . writeContentModifications ( writer , patch . getModifications ( ) ) ; } protected static void writeContentModifications ( final XMLExtendedStreamWriter writer , final Collection < ContentModification > modifications ) throws XMLStreamException { } protected void doReadElement ( final XMLExtendedStreamReader reader , final PatchBuilderFactory factory ) 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 , boolean addOn ) throws XMLStreamException { } static void parseElementProvider ( final XMLExtendedStreamReader reader , PatchElementImpl patchElement , Patch . PatchType patchType , boolean isAddOn ) 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 { }

Fix:
if ( elementPatchType == ( PatchType . ONE_OFF ) ) {