Buggy code:
private HtmlPane htmlPane ; private BrowserPane browserPane ; private JPanel padding ; private UndoManager undoManager = new UndoManager ( ) ; public boolean isRichText ; public boolean isMarkdown ; private boolean maybeImporting ; final Color kDividerColor = Color . decode ( "#dbdbdb" ) ; private final FocusListener editorFocusListener = new FocusListener ( ) { @ Override public void focusGained ( FocusEvent e ) { } @ Override public void focusLost ( FocusEvent e ) { } } ; private final AbstractAction boldAction = new AbstractAction ( ) { StyledEditorKit . BoldAction a = new StyledEditorKit . BoldAction ( ) ; @ Override public void actionPerformed ( ActionEvent e ) { } } ; private final AbstractAction italicAction = new AbstractAction ( ) { StyledEditorKit . ItalicAction a = new StyledEditorKit . ItalicAction ( ) ; @ Override public void actionPerformed ( ActionEvent e ) { } } ; private final AbstractAction underlineAction = new AbstractAction ( ) { StyledEditorKit . UnderlineAction a = new StyledEditorKit . UnderlineAction ( ) ; @ Override public void actionPerformed ( ActionEvent e ) { } } ; private final AbstractAction strikethroughAction = new AbstractAction ( ) { @ Override public void actionPerformed ( ActionEvent e ) { } } ; private final AbstractAction strikethroughRearrangeAction = new AbstractAction ( ) { @ Override public void actionPerformed ( ActionEvent event ) { } } ; private final AbstractAction increaseFontSizeAction = new AbstractAction ( ) { @ Override public void actionPerformed ( ActionEvent e ) { } } ; private final AbstractAction decreaseFontSizeAction = new AbstractAction ( ) { @ Override public void actionPerformed ( ActionEvent e ) { } } ; private EditorEventListener eeListener ; private CustomEditor . NoteAttachmentTransferHandler attachmentTransferHandler ; class NoteAttachmentTransferHandler extends AttachmentTransferHandler { public NoteAttachmentTransferHandler ( EditorEventListener listener ) { } @ Override public boolean canImport ( TransferHandler . TransferSupport info ) { } } private static class CustomDocument extends DefaultStyledDocument { private static final long serialVersionUID = 2807153134148093523L ; @ Override public void insertString ( int offs , String str , AttributeSet a ) throws BadLocationException { } } private final CustomMouseListener paddingClick = new CustomMouseListener ( ) { @ Override public void mouseClicked ( MouseEvent e ) { } } ; public boolean isRichText ( ) { } public void setMarkdown ( boolean b ) { } public boolean maybeImporting ( ) { } public JTextPane getTextPane ( ) { } public void setEditorEventListener ( EditorEventListener l ) { } @ SuppressWarnings ( "serial" ) public CustomEditor ( ) { } void insertNewline ( int position ) { } AttributeSet getAttributes ( int position ) { } class CustomTextPane extends JTextPane implements ClipboardOwner { private static final long serialVersionUID = - 5388021236896195540L ; private String prevRtfCopy = "" ; public void setClipboardContents ( String aString ) { } public void setClipboardContentsRtf ( String rtf ) { } public String getClipboardContents ( ) { } private class CPPInfo { Document doc ; int pos ; int len ; int start ; int end ; int selLen ; int adjust ; boolean hasSelection ; public CPPInfo ( ) { } } @ Override public void cut ( ) { } @ Override public void copy ( ) { } @ Override public void paste ( ) { String s = getClipboardContents ( ) ; if ( ( s . isEmpty ( ) ) && ( ! ( prevRtfCopy . isEmpty ( ) ) ) ) { s = prevRtfCopy ; } if ( ! ( s . isEmpty ( ) ) ) { try { CustomEditor . CustomTextPane . CPPInfo i = new CustomEditor . CustomTextPane . CPPInfo ( ) ; if ( i . hasSelection ) { i . doc . remove ( i . start , i . selLen ) ; } i . pos -= i . adjust ; <START_BUG> if ( ! ( "{\\rtf" . equals ( s . substring ( 0 , 5 ) ) ) ) { <END_BUG> i . doc . insertString ( i . pos , s , null ) ; } else { if ( isMarkdown ) { String plain = Note . plainTextContents ( s ) ; i . doc . insertString ( i . pos , plain , null ) ; return ; } CustomEditor . CustomDocument d = new CustomEditor . CustomDocument ( ) ; try { RtfUtil . putRtf ( d , s , 0 ) ; Element [ ] elems = d . getRootElements ( ) ; for ( Element e : elems ) { for ( int idx = 0 , count = e . getElementCount ( ) ; idx < ( count - 1 ) ; idx ++ ) { Element sub = e . getElement ( idx ) ; if ( "paragraph" . equals ( sub . getName ( ) ) ) { int start = sub . getStartOffset ( ) ; int end = sub . getEndOffset ( ) ; AttributeSet as = d . getCharacterElement ( start ) . getAttributes ( ) ; if ( end > start ) { String text = d . getText ( start , ( end - start ) ) ; i . doc . insertString ( i . pos , text , as ) ; i . pos += end - start ; isRichText = true ; } } } } } catch ( IOException e ) { CustomEditor . LOG . severe ( ( "Fail:<seq2seq4repair_space>" + e ) ) ; } } } catch ( BadLocationException e ) { CustomEditor . LOG . severe ( ( "Fail:<seq2seq4repair_space>" + e ) ) ; } } } @ Override public void lostOwnership ( Clipboard clipboard , Transferable contents ) { } } private void createNote ( ) { } private void markdownStyleCommand ( String codeStart , String codeEnd ) { } private void shiftFontSize ( final int delta ) { } @ Subscribe public void handleStyleCommandEvent ( StyleCommandEvent e ) { } public void turnToPlainText ( ) { }

Fix:
if ( ( ( s . length ( ) ) < 5 ) || ( ! ( "{\\rtf" . equals ( s . substring ( 0 , 5 ) ) ) ) ) {