Buggy code:
@ Dependent @ Stateless public class HtmlMaterialController { @ Inject private HtmlMaterialDAO htmlMaterialDAO ; @ Inject private HtmlMaterialPropertyDAO htmlMaterialPropertyDAO ; @ Inject private HtmlMaterialExtensionPropertyDAO htmlMaterialExtensionPropertyDAO ; @ Inject private HtmlMaterialRevisionDAO htmlMaterialRevisionDAO ; @ Inject private HtmlMaterialRevisionPropertyDAO htmlMaterialRevisionPropertyDAO ; @ Inject private HtmlMaterialRevisionExtensionPropertyDAO htmlMaterialRevisionExtensionPropertyDAO ; @ Inject @ Any private Instance < CoOpsDiffAlgorithm > algorithms ; @ Inject private Event < HtmlMaterialCreateEvent > materialCreateEvent ; @ Inject private Event < HtmlMaterialDeleteEvent > materialDeleteEvent ; @ Inject private Event < HtmlMaterialUpdateEvent > materialUpdateEvent ; public HtmlMaterial createHtmlMaterial ( String title , String html , String contentType , Long revisionNumber ) { } public HtmlMaterial findHtmlMaterialById ( Long id ) { } public HtmlMaterial updateHtmlMaterialTitle ( HtmlMaterial htmlMaterial , String title ) { } public void deleteHtmlMaterial ( HtmlMaterial htmlMaterial ) { } public HtmlMaterial updateHtmlMaterialHtml ( HtmlMaterial htmlMaterial , String html ) { } public HtmlMaterial updateHtmlMaterialToRevision ( HtmlMaterial htmlMaterial , String html , Long revisionNumber , boolean removeNewerRevisions ) { } public String getRevisionHtml ( HtmlMaterial htmlMaterial , long revision ) throws CoOpsInternalErrorException { String result = htmlMaterial . getHtml ( ) ; long baselineRevision = htmlMaterial . getRevisionNumber ( ) ; CoOpsDiffAlgorithm algorithm = findAlgorithm ( "dmp" ) ; if ( revision < baselineRevision ) { <START_BUG> List < HtmlMaterialRevision > revisions = htmlMaterialRevisionDAO . listByFileAndRevisionGtAndRevisonLeOrderedByRevision ( htmlMaterial , revision , baselineRevision ) ; <END_BUG> for ( int i = ( revisions . size ( ) ) - 1 ; i >= 0 ; i -- ) { HtmlMaterialRevision patchingRevision = revisions . get ( i ) ; try { if ( ( patchingRevision . getData ( ) ) != null ) { result = algorithm . unpatch ( result , patchingRevision . getData ( ) ) ; } } catch ( CoOpsConflictException e ) { throw new CoOpsInternalErrorException ( ( "Patch<seq2seq4repair_space>failed<seq2seq4repair_space>when<seq2seq4repair_space>building<seq2seq4repair_space>material<seq2seq4repair_space>revision<seq2seq4repair_space>number<seq2seq4repair_space>" + revision ) ) ; } } } else { List < HtmlMaterialRevision > revisions = htmlMaterialRevisionDAO . listByFileAndRevisionGtAndRevisonLeOrderedByRevision ( htmlMaterial , baselineRevision , revision ) ; for ( HtmlMaterialRevision patchingRevision : revisions ) { try { if ( ( patchingRevision . getData ( ) ) != null ) { result = algorithm . patch ( result , patchingRevision . getData ( ) ) ; } } catch ( CoOpsConflictException e ) { throw new CoOpsInternalErrorException ( ( "Patch<seq2seq4repair_space>failed<seq2seq4repair_space>when<seq2seq4repair_space>building<seq2seq4repair_space>material<seq2seq4repair_space>revision<seq2seq4repair_space>number<seq2seq4repair_space>" + revision ) ) ; } } } return result ; } public long lastHtmlMaterialRevision ( HtmlMaterial htmlMaterial ) { } public HtmlMaterialRevision createRevision ( HtmlMaterial htmlMaterial , String sessionId , Long patchRevisionNumber , Date date , String patch , String checksum ) { } private void deleteRevision ( HtmlMaterialRevision revision ) { } public List < HtmlMaterialProperty > listPropertiesByMaterial ( HtmlMaterial htmlMaterial ) { } public List < HtmlMaterialRevision > listRevisionsAfter ( HtmlMaterial htmlMaterial , Long revisionNumber ) { } public HtmlMaterialProperty setProperty ( HtmlMaterial htmlMaterial , String key , String value ) { } public HtmlMaterialRevisionProperty createRevisionProperty ( HtmlMaterialRevision htmlMaterialRevision , String key , String value ) { } public List < HtmlMaterialRevisionProperty > listRevisionProperties ( HtmlMaterialRevision htmlMaterialRevision ) { } public HtmlMaterialRevisionExtensionProperty createRevisionExtensionProperty ( HtmlMaterialRevision htmlMaterialRevision , String key , String value ) { } public List < HtmlMaterialRevisionExtensionProperty > listRevisionExtensionProperties ( HtmlMaterialRevision htmlMaterialRevision ) { } public void setExtensionProperty ( HtmlMaterial htmlMaterial , String key , String value ) { } public CoOpsDiffAlgorithm findAlgorithm ( String algorithmName ) { } public CoOpsDiffAlgorithm findAlgorithm ( List < String > algorithmNames ) { } private Map < String , CoOpsDiffAlgorithm > getAlgorithmMap ( ) { } }

Fix:
List < HtmlMaterialRevision > revisions = htmlMaterialRevisionDAO . listByFileAndRevisionGeAndRevisonLtOrderedByRevision ( htmlMaterial , revision , baselineRevision ) ;