Buggy code:
writer . writeCharacters ( patch . getDescription ( ) ) ; writer . writeEndElement ( ) ; final Identity identity = patch . getIdentity ( ) ; writer . writeStartElement ( PatchXml_1_1 . Element . IDENTITY . name ) ; writer . writeAttribute ( PatchXml_1_1 . Attribute . NAME . name , identity . getName ( ) ) ; writer . writeAttribute ( PatchXml_1_1 . Attribute . VERSION . name , identity . getVersion ( ) ) ; if ( ! ( identity . getRequires ( ) . isEmpty ( ) ) ) { writer . writeStartElement ( PatchXml_1_1 . Element . REQUIRES . name ) ; for ( String patchId : identity . getRequires ( ) ) { writer . writeStartElement ( PatchXml_1_1 . Element . PATCH . name ) ; writer . writeAttribute ( PatchXml_1_1 . Attribute . ID . name , patchId ) ; writer . writeEndElement ( ) ; } writer . writeEndElement ( ) ; } writer . writeEndElement ( ) ; final PatchType type = patch . getPatchType ( ) ; if ( type == ( PatchType . ONE_OFF ) ) { writer . writeEmptyElement ( PatchXml_1_1 . Element . NO_UPGRADE . name ) ; } else { writer . writeStartElement ( PatchXml_1_1 . Element . UPGRADE . name ) ; writer . writeAttribute ( PatchXml_1_1 . Attribute . TO_VERSION . name , patch . getResultingVersion ( ) ) ; writer . writeEndElement ( ) ; } final List < PatchElement > elements = patch . getElements ( ) ; for ( PatchElement element : elements ) { writer . writeStartElement ( PatchXml_1_1 . Element . ELEMENT . name ) ; writer . writeAttribute ( PatchXml_1_1 . Attribute . ID . name , element . getId ( ) ) ; if ( ( element . getDescription ( ) ) != null ) { writer . writeStartElement ( PatchXml_1_1 . 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 ( ) ) ) ) ; } if ( provider . isAddOn ( ) ) { writer . writeStartElement ( PatchXml_1_1 . Element . ADD_ON . name ) ; } else { writer . writeStartElement ( PatchXml_1_1 . Element . LAYER . name ) ; } writer . writeAttribute ( PatchXml_1_1 . Attribute . NAME . name , provider . getName ( ) ) ; writer . writeAttribute ( PatchXml_1_1 . Attribute . VERSION . name , provider . getVersion ( ) ) ; if ( ! ( provider . getRequires ( ) . isEmpty ( ) ) ) { writer . writeStartElement ( PatchXml_1_1 . Element . REQUIRES . name ) ; for ( String elementId : provider . getRequires ( ) ) { writer . writeStartElement ( PatchXml_1_1 . Element . ELEMENT . name ) ; writer . writeAttribute ( PatchXml_1_1 . Attribute . ID . name , elementId ) ; writer . writeEndElement ( ) ; } writer . writeEndElement ( ) ; } writer . writeEndElement ( ) ; final Patch . PatchType upgrade = element . getPatchType ( ) ; if ( upgrade == ( PatchType . ONE_OFF ) ) { writer . writeEmptyElement ( PatchXml_1_1 . Element . NO_UPGRADE . name ) ; } else { writer . writeEmptyElement ( PatchXml_1_1 . Element . UPGRADE . name ) ; writer . writeAttribute ( PatchXml_1_1 . Attribute . TO_VERSION . name , element . getResultingVersion ( ) ) ; } final List < ContentModification > bundlesAdd = new ArrayList < ContentModification > ( ) ; final List < ContentModification > bundlesUpdate = new ArrayList < ContentModification > ( ) ; final List < ContentModification > bundlesRemove = new ArrayList < ContentModification > ( ) ; final List < ContentModification > miscAdd = new ArrayList < ContentModification > ( ) ; final List < ContentModification > miscUpdate = new ArrayList < ContentModification > ( ) ; final List < ContentModification > miscRemove = new ArrayList < ContentModification > ( ) ; final List < ContentModification > modulesAdd = new ArrayList < ContentModification > ( ) ; final List < ContentModification > modulesUpdate = new ArrayList < ContentModification > ( ) ; final List < ContentModification > modulesRemove = new ArrayList < ContentModification > ( ) ; <START_BUG> for ( final ContentModification mod : patch . getModifications ( ) ) { <END_BUG> final ModificationType modificationType = mod . getType ( ) ; final ContentType contentType = mod . getItem ( ) . getContentType ( ) ; switch ( contentType ) { case BUNDLE : switch ( modificationType ) { case ADD : bundlesAdd . add ( mod ) ; break ; case MODIFY : bundlesUpdate . add ( mod ) ; break ; case REMOVE : bundlesRemove . add ( mod ) ; break ; } break ; case MODULE : switch ( modificationType ) { case ADD : modulesAdd . add ( mod ) ; break ; case MODIFY : modulesUpdate . add ( mod ) ; break ; case REMOVE : modulesRemove . add ( mod ) ; break ; } break ; case MISC : switch ( modificationType ) { case ADD : miscAdd . add ( mod ) ; break ; case MODIFY : miscUpdate . add ( mod ) ; break ; case REMOVE : miscRemove . add ( mod ) ; break ; } break ; } } if ( ( ( ! ( modulesAdd . isEmpty ( ) ) ) || ( ! ( modulesUpdate . isEmpty ( ) ) ) ) || ( ! ( modulesRemove . isEmpty ( ) ) ) ) { writer . writeStartElement ( PatchXml_1_1 . Element . MODULES . name ) ; writeSlottedItems ( writer , PatchXml_1_1 . Element . ADDED , modulesAdd ) ;

Fix:
for ( final ContentModification mod : element . getModifications ( ) ) {