Buggy code:
@ Deprecated public class GenomeSequenceMongoDBAdaptor extends MongoDBAdaptor implements GenomeSequenceDBAdaptor { public GenomeSequenceMongoDBAdaptor ( DB db ) { } public GenomeSequenceMongoDBAdaptor ( DB db , String species , String version ) { } private int getChunk ( int position ) { } private int getOffset ( int position ) { } public static String getComplementarySequence ( String sequence ) { } @ Override public QueryResult getByRegion ( String chromosome , int start , int end , QueryOptions options ) { } @ Override public List < QueryResult > getAllByRegionList ( List < Region > regions , QueryOptions options ) { String chunkIdSuffix = ( ( Integer . parseInt ( applicationProperties . getProperty ( ( ( "CELLBASE." + ( version . toUpperCase ( ) ) ) + ".GENOME_SEQUENCE.CHUNK_SIZE" ) , "2000" ) ) ) // 1000 ) + "k" ; List < DBObject > queries = new ArrayList < > ( ) ; List < String > ids = new ArrayList ( regions . size ( ) ) ; List < String > chunkIds ; List < Integer > integerChunkIds ; for ( Region region : regions ) { chunkIds = new ArrayList < > ( ) ; integerChunkIds = new ArrayList < > ( ) ; if ( ( region . getStart ( ) ) < 1 ) { region . setStart ( 1 ) ; } if ( ( region . getEnd ( ) ) < 1 ) { region . setEnd ( 1 ) ; } int regionChunkStart = getChunk ( region . getStart ( ) ) ; int regionChunkEnd = getChunk ( region . getEnd ( ) ) ; for ( int chunkId = regionChunkStart ; chunkId <= regionChunkEnd ; chunkId ++ ) { String chunkIdStr = ( ( ( ( region . getChromosome ( ) ) + "_" ) + chunkId ) + "_" ) + chunkIdSuffix ; chunkIds . add ( chunkIdStr ) ; integerChunkIds . add ( chunkId ) ; } QueryBuilder builder = QueryBuilder . start ( "sequenceName" ) . is ( region . getChromosome ( ) ) . and ( "chunkId" ) . in ( chunkIds ) ; queries . add ( builder . get ( ) ) ; ids . add ( region . toString ( ) ) ; logger . info ( builder . get ( ) . toString ( ) ) ; } List < QueryResult > queryResults = executeQueryList ( ids , queries , options ) ; for ( int i = 0 ; i < ( regions . size ( ) ) ; i ++ ) { Region region = regions . get ( i ) ; QueryResult queryResult = queryResults . get ( i ) ; BasicDBList list = ( ( BasicDBList ) ( queryResult . get ( "result" ) ) ) ; System . out . println ( list . toString ( ) ) ; StringBuilder sb = new StringBuilder ( ) ; for ( int j = 0 ; j < ( list . size ( ) ) ; j ++ ) { BasicDBObject chunk = ( ( BasicDBObject ) ( list . get ( j ) ) ) ; sb . append ( chunk . get ( "sequence" ) ) ; } int startStr = getOffset ( region . getStart ( ) ) ; int endStr = ( ( getOffset ( region . getStart ( ) ) ) + ( ( region . getEnd ( ) ) - ( region . getStart ( ) ) ) ) + 1 ; String subStr = "" ; <START_BUG> if ( ( getChunk ( region . getEnd ( ) ) ) > 0 ) { <END_BUG> if ( ( ( sb . toString ( ) . length ( ) ) > 0 ) && ( ( sb . toString ( ) . length ( ) ) >= endStr ) ) { subStr = sb . toString ( ) . substring ( startStr , endStr ) ; } } else { if ( ( ( sb . toString ( ) . length ( ) ) > 0 ) && ( ( ( sb . toString ( ) . length ( ) ) + 1 ) >= endStr ) ) { subStr = sb . toString ( ) . substring ( ( startStr - 1 ) , ( endStr - 1 ) ) ; } } GenomeSequenceFeature genomeSequenceFeature = new GenomeSequenceFeature ( region . getChromosome ( ) , region . getStart ( ) , region . getEnd ( ) , 1 , ( ( BasicDBObject ) ( list . get ( 0 ) ) ) . getString ( "sequenceType" ) , ( ( BasicDBObject ) ( list . get ( 0 ) ) ) . getString ( "assembly" ) , subStr ) ; queryResult . setResult ( genomeSequenceFeature ) ; } return queryResults ; } @ Override public String getRevComp ( String sequence ) { } private List < GenomeSequenceChunk > executeQuery ( DBObject query ) { } }

Fix:
if ( ( getChunk ( region . getStart ( ) ) ) > 0 ) {