CharSequence (final String substring) { final long myTime = System.currentTimeMillis() + 500; return new StringUtil.BombedCharSequence(substring) { @Override protected void checkCanceled() { //todo[anna] if (ApplicationManager.getApplication().isHeadlessEnvironment()) return; long l = System.currentTimeMillis(); if (l >= myTime) { throw new ProcessCanceledException(); } } }; }