Charset (@Nullable Project project, @Nullable VirtualFile file, @NotNull CharSequence content) { Thread prev = detectThreads.put(file, Thread.currentThread()); try { if (prev != null) { exception.set(new Throwable(file +" has two detection threads: "+prev +" and "+ Thread.currentThread()+"\nThe full thread dump:\n"+ThreadDumper.dumpThreadsToString())); } TimeoutUtil.sleep(1000); return US_ASCII; } finally { detectThreads.remove(file); } }