Buggy code:
public class StyledDocumentWriter { private static final Logger LOG = Logger . getLogger ( StyledDocumentWriter . class . getSimpleName ( ) ) ; private static EditorCookie getEditorCookie ( DataObject dataObject ) { } public static EditorKit getEditorKit ( DataObject dataObject ) { } public static ArrayList < String > readFileObjectIntoLines ( FileObject fo , Charset charset , String lineEnding ) throws FileAccessException { } public static void writeFile ( FileObject fo , Charset charset , String content ) throws FileAccessException { } public static void writeOnFile ( FileObject fo , String content ) throws FileAccessException { } public static void writeOnFileWithLines ( FileObject fo , Charset charset , List < String > lines ) throws FileAccessException { } public static void writeOnFileWithLines ( File file , Charset charset , List < String > lines ) throws FileAccessException { } public static void writeWithEditorKit ( FileInfo info ) throws FileAccessException { EditorCookie cookie = info . getCookie ( ) ; EditorKit kit = StyledDocumentWriter . getEditorKit ( info . getDataObject ( ) ) ; StyledDocument document = null ; int caretPosition ; try { document = cookie . openDocument ( ) ; } catch ( IOException ex ) { throw new FileAccessException ( ( "Document<seq2seq4repair_space>could<seq2seq4repair_space>not<seq2seq4repair_space>be<seq2seq4repair_space>loaded:<seq2seq4repair_space>" + ( ex . getMessage ( ) ) ) ) ; } try ( InputStream is = new ByteArrayInputStream ( info . getContentAsBytes ( ) ) ) { Caret caret = info . getCaret ( ) ; caretPosition = info . getCurrentCaretPosition ( ) ; document . remove ( 0 , document . getLength ( ) ) ; StyledDocumentWriter . LOG . log ( Level . INFO , "Write<seq2seq4repair_space>to<seq2seq4repair_space>\"is\":<seq2seq4repair_space>{0}" , is ) ; <START_BUG> StyledDocumentWriter . LOG . log ( Level . INFO , "Write<seq2seq4repair_space>to<seq2seq4repair_space>\"document\":<seq2seq4repair_space>{0}" , is ) ; <END_BUG> kit . read ( is , document , document . getLength ( ) ) ; cookie . saveDocument ( ) ; info . getFileObject ( ) . setAttribute ( ENCODING_SETTING , info . getCharset ( ) . name ( ) ) ; caretPosition -= info . getCaretOffset ( ) ; if ( caretPosition < ( document . getLength ( ) ) ) { StyledDocumentWriter . LOG . log ( Level . INFO , "Moving<seq2seq4repair_space>caret<seq2seq4repair_space>position<seq2seq4repair_space>to:<seq2seq4repair_space>{0}<seq2seq4repair_space>//<seq2seq4repair_space>{1}" , new Object [ ] { caretPosition , document . getLength ( ) } ) ; caret . setDot ( caretPosition ) ; } } catch ( BadLocationException | IOException ex ) { throw new FileAccessException ( ( "Document<seq2seq4repair_space>could<seq2seq4repair_space>not<seq2seq4repair_space>be<seq2seq4repair_space>saved:<seq2seq4repair_space>" + ( ex . getMessage ( ) ) ) ) ; } Reformat reformat = Reformat . get ( document ) ; reformat . lock ( ) ; try { reformat . reformat ( 0 , document . getLength ( ) ) ; } catch ( BadLocationException ex ) { StyledDocumentWriter . LOG . log ( Level . SEVERE , "AutoFormat<seq2seq4repair_space>on<seq2seq4repair_space>document<seq2seq4repair_space>not<seq2seq4repair_space>possible:<seq2seq4repair_space>{0}" , ex . getMessage ( ) ) ; } finally { reformat . unlock ( ) ; try { cookie . saveDocument ( ) ; } catch ( IOException ex ) { throw new FileAccessException ( ( "Document<seq2seq4repair_space>could<seq2seq4repair_space>not<seq2seq4repair_space>be<seq2seq4repair_space>saved:<seq2seq4repair_space>" + ( ex . getMessage ( ) ) ) ) ; } } } public static void writeWithFilesystemAPI ( FileInfo info , List < String > lines ) throws FileAccessException { } public static void writeWithString ( FileInfo info ) throws FileAccessException { } }

Fix:
StyledDocumentWriter . LOG . log ( Level . INFO , "Write<seq2seq4repair_space>to<seq2seq4repair_space>\"document\":<seq2seq4repair_space>{0}" , document ) ;