Buggy code:
public abstract class FormattableDocument implements IFormattableDocument { private final TextSegmentSet < ITextReplacer > replacers ; protected FormattableDocument ( ) { } @ Override public void addReplacer ( ITextReplacer replacer ) { } @ Override public ISemanticRegion append ( ISemanticRegion token , Procedure1 < ? super IHiddenRegionFormatter > after ) { } @ Override public < T extends EObject > T append ( T owner , Procedure1 < ? super IHiddenRegionFormatter > after ) { } protected String applyTextReplacements ( Iterable < ITextReplacement > replacements ) { } protected ITextReplacerContext createReplacements ( ITextReplacerContext previous ) { Integer maxLineWidth = getRequest ( ) . getPreferences ( ) . getPreference ( maxLineWidth ) ; ITextReplacerContext context = previous . withDocument ( this ) ; ITextReplacerContext wrappable = null ; Set < ITextReplacer > wrapped = Sets . newHashSet ( ) ; LinkedList < ITextReplacer > queue = new LinkedList < ITextReplacer > ( ) ; for ( ITextReplacer replacer : replacers ) queue . add ( replacer ) ; while ( ! ( queue . isEmpty ( ) ) ) { ITextReplacer replacer = queue . poll ( ) ; context = context . withReplacer ( replacer ) ; if ( ( wrappable != null ) && ( needsAutowrap ( wrappable , context , maxLineWidth ) ) ) { while ( context != wrappable ) { ITextReplacer r = context . getReplacer ( ) ; <START_BUG> if ( r != null ) { <END_BUG> queue . addFirst ( r ) ; } context = context . getPreviousContext ( ) ; } replacer = context . getReplacer ( ) ; context . setAutowrap ( true ) ; wrappable = null ; } ITextReplacerContext nextContext = replacer . createReplacements ( context ) ; Integer canAutowrap = context . canAutowrap ( ) ; if ( ( ( ( canAutowrap != null ) && ( canAutowrap >= 0 ) ) && ( ! ( context . isAutowrap ( ) ) ) ) && ( ! ( wrapped . contains ( replacer ) ) ) ) { boolean can = true ; if ( wrappable != null ) { int lastEndOffset = ( wrappable . canAutowrap ( ) ) + ( wrappable . getReplacer ( ) . getRegion ( ) . getEndOffset ( ) ) ; int thisEndOffset = canAutowrap + ( context . getReplacer ( ) . getRegion ( ) . getEndOffset ( ) ) ; can = lastEndOffset < thisEndOffset ; } if ( can ) { wrappable = context ; wrapped . add ( replacer ) ; } } context = nextContext ; } return context . withDocument ( previous . getDocument ( ) ) ; } protected TextSegmentSet < ITextReplacer > createTextReplacerSet ( ) { } @ Override public void formatConditionally ( EObject owner , ISubFormatter ... formatters ) { } @ Override public void formatConditionally ( int offset , int length , ISubFormatter ... formatters ) throws FormattingNotApplicableException { } public ITypedPreferenceValues getPreferences ( ) { } public ITextRegionAccess getTextRegionAccess ( ) { } protected boolean needsAutowrap ( ITextReplacerContext wrappable , ITextReplacerContext context , int maxLineWidth ) { } @ Override public ISemanticRegion prepend ( ISemanticRegion token , Procedure1 < ? super IHiddenRegionFormatter > before ) { } @ Override public < T extends EObject > T prepend ( T owner , Procedure1 < ? super IHiddenRegionFormatter > before ) { } @ Override public List < ITextReplacement > renderToTextReplacements ( ) { } @ Override public IHiddenRegion set ( IHiddenRegion hiddenRegion , Procedure1 < ? super IHiddenRegionFormatter > init ) { } @ Override public ISemanticRegion surround ( ISemanticRegion token , Procedure1 < ? super IHiddenRegionFormatter > beforeAndAfter ) { } @ Override public < T extends EObject > T surround ( T owner , Procedure1 < ? super IHiddenRegionFormatter > beforeAndAfter ) { } @ Override public String toString ( ) { } @ Override public IFormattableSubDocument withReplacerFilter ( Predicate < ? super ITextReplacer > filter ) { } }

Fix:
if ( ( r != null ) && ( ( replacers . get ( r ) ) == r ) ) {