void () { AtomicReference<List<Integer>> minOffsets = new AtomicReference<>(); AtomicInteger failPrinted = new AtomicInteger(); String text = StringUtil.repeat("blah", 1000); IntStream.range(0, 1_000).parallel().forEach(iter -> { DocumentEx doc = new DocumentImpl(text, true); List<Integer> offsets = new ArrayList<>(); try { List<Integer> oldOffsets = minOffsets.get(); int n = oldOffsets == null ? 261 : oldOffsets.size()/4; //if (iter%1000==0) System.out.println(iter +" (length="+n+")"); List<RangeMarker> markers = new ArrayList<>(); for (int i = 0; i < n; i++) { int limit = doc.getTextLength() + 1; int offset = raaand(limit); int startOffset = 1+raaand(limit - 3); int endOffset = startOffset + 1 + raaand(limit - startOffset - 2); int targetOffset = raaand(limit - (endOffset - startOffset + 1)); if (targetOffset >= startOffset) targetOffset += endOffset - startOffset+1; offsets.add(offset); offsets.add(startOffset); offsets.add(endOffset); offsets.add(targetOffset); RangeMarker marker = doc.createRangeMarker(offset, offset); markers.add(marker); doc.moveText(startOffset, endOffset, targetOffset); assertTrue(marker.toString(), marker.isValid()); for (RangeMarker rm : markers) { assertTrue(rm.isValid()); } } } catch (AssertionError e) { List<Integer> updated = minOffsets.updateAndGet(oldMarkers -> oldMarkers == null || offsets.size() < oldMarkers.size() ? offsets : oldMarkers); if (updated == offsets && failPrinted.getAndIncrement() < 10) { System.err.println("Aha: " + offsets.size() + " " + e+"\n"+minOffsets); } } catch (Throwable e) { e.printStackTrace(); throw e; } }); if (minOffsets.get() != null) { System.err.println("Moves and offsets ("+minOffsets.get().size()+"): " + minOffsets); fail(); } }