Buggy code:
@ Property ( "otherNumbers" ) public void setOtherNumbers ( String otherNumbers ) { } @ JavaHandler public void setAllOtherNumbers ( Map < String , String > otherNumbers ) throws IOException , JsonParseException , JsonMappingException { } @ Adjacency ( label = IsSourceCopyOf . label , direction = Direction . OUT ) public Copy getSourceCopy ( ) { } @ Adjacency ( label = IsSourceCopyOf . label , direction = Direction . IN ) public Iterable < Copy > getDerivatives ( ) { } @ Adjacency ( label = IsSourceCopyOf . label , direction = Direction . OUT ) public void setSourceCopy ( Copy sourceCopy ) { } @ Adjacency ( label = IsComasterOf . label , direction = Direction . OUT ) public Copy getComasterCopy ( ) { } @ Adjacency ( label = IsComasterOf . label , direction = Direction . OUT ) public void setComasterCopy ( Copy comasterCopy ) { } @ Adjacency ( label = IsFileOf . label , direction = Direction . IN ) public Iterable < File > getFiles ( ) { } @ Adjacency ( label = IsFileOf . label , direction = Direction . IN ) public File getFile ( ) { } @ JavaHandler public CameraData getCameraData ( ) { } @ JavaHandler public ImageFile getImageFile ( ) { } @ JavaHandler public SoundFile getSoundFile ( ) { } @ Adjacency ( label = DescriptionOf . label , direction = Direction . IN ) public CameraData addCameraData ( ) { } @ Adjacency ( label = IsFileOf . label , direction = Direction . IN ) public File addFile ( ) { } @ Adjacency ( label = IsFileOf . label , direction = Direction . IN ) public ImageFile addImageFile ( ) { } @ Adjacency ( label = IsFileOf . label , direction = Direction . IN ) public SoundFile addSoundFile ( ) { } @ JavaHandler File addFile ( Path source , String mimeType ) throws IOException { } @ JavaHandler File addLegacyDossFile ( Path dossPath , String mimeType ) throws IOException { } @ JavaHandler File addFile ( Writable contents , String mimeType ) throws IOException { } @ Adjacency ( label = IsFileOf . label , direction = Direction . IN ) void removeFile ( final File file ) { } @ Adjacency ( label = IsCopyOf . label ) public Work getWork ( ) { } @ Adjacency ( label = Represents . label ) public Iterable < Work > getRepresentedWorks ( ) { } @ JavaHandler Copy deriveJp2ImageCopy ( Path jp2Converter , Path imgConverter ) throws IOException , Exception , IllegalStateException , InterruptedException ; @ JavaHandler Copy derivePdfCopy ( Path pdfConverter , Path stylesheet , Path altStylesheet ) throws NoSuchBlobException , IOException , IllegalStateException , InterruptedException { } @ JavaHandler Copy derivePdfCopy ( CopyRole copyRole , Reader ... stylesheets ) throws IOException { } abstract class Impl extends Node . Impl implements Copy , JavaHandlerContext < Vertex > { static final Logger log = LoggerFactory . getLogger ( Copy . class ) ; static ObjectMapper mapper = new ObjectMapper ( ) ; @ Override public File addFile ( Path source , String mimeType ) throws IOException { } @ Override public File addLegacyDossFile ( Path dossPath , String mimeType ) throws IOException { } @ Override public File addFile ( Writable contents , String mimeType ) throws IOException { } private void storeFile ( File file , Writable contents , String mimeType ) throws IOException { } private void storeLegacyDossFile ( File file , Path dossPath , String mimeType ) throws IOException { } @ Override public Copy deriveJp2ImageCopy ( Path jp2Converter , Path imgConverter ) throws IOException , Exception , IllegalStateException , InterruptedException { ImageFile imgFile = this . getImageFile ( ) ; String mimeType = imgFile . getMimeType ( ) ; if ( ! ( ( mimeType . equals ( "image//tiff" ) ) || ( mimeType . equals ( "image//jpeg" ) ) ) ) { throw new IllegalStateException ( ( ( this . getWork ( ) . getObjId ( ) ) + "<seq2seq4repair_space>master<seq2seq4repair_space>is<seq2seq4repair_space>not<seq2seq4repair_space>a<seq2seq4repair_space>tiff<seq2seq4repair_space>or<seq2seq4repair_space>jpeg.<seq2seq4repair_space>You<seq2seq4repair_space>may<seq2seq4repair_space>not<seq2seq4repair_space>generate<seq2seq4repair_space>a<seq2seq4repair_space>jpeg2000<seq2seq4repair_space>from<seq2seq4repair_space>anything<seq2seq4repair_space>but<seq2seq4repair_space>a<seq2seq4repair_space>tiff<seq2seq4repair_space>or<seq2seq4repair_space>a<seq2seq4repair_space>jpeg" ) ) ; } Path stage = null ; try { stage = Files . createTempDirectory ( "amberdb-derivative" ) ; Long imgBlobId = ( ( this . getFile ( ) ) == null ) ? null : this . getFile ( ) . getBlobId ( ) ; BlobStore doss = AmberSession . ownerOf ( g ( ) ) . getBlobStore ( ) ; Path jp2ImgPath = generateJp2Image ( doss , jp2Converter , imgConverter , stage , imgBlobId ) ; Copy ac = null ; if ( jp2ImgPath != null ) { Work work = this . getWork ( ) ; Iterable < Copy > derivatives = this . getDerivatives ( ) ; <START_BUG> if ( ( Iterables . size ( derivatives ) ) != 0 ) { <END_BUG> ac = work . addCopy ( jp2ImgPath , ACCESS_COPY , "image//jp2" ) ; ac . setSourceCopy ( this ) ; } else { ac = Iterables . get ( derivatives , 0 ) ; ac . getImageFile ( ) . put ( jp2ImgPath ) ; } ImageFile acf = ac . getImageFile ( ) ; acf . setLocation ( jp2ImgPath . toString ( ) ) ; acf . setImageLength ( imgFile . getImageLength ( ) ) ; acf . setImageWidth ( imgFile . getImageWidth ( ) ) ; acf . setResolution ( imgFile . getResolution ( ) ) ; acf . setFileFormat ( "jpeg2000" ) ; acf . setFileSize ( Files . size ( jp2ImgPath ) ) ; } return ac ; } catch ( Exception e ) { throw e ; } finally { java . io . File [ ] files = stage . toFile ( ) . listFiles ( ) ; if ( files != null ) { for ( java . io . File f : files ) { f . delete ( ) ; } }

Fix:
if ( ( Iterables . size ( derivatives ) ) == 0 ) {