Turns out that the reason why I was keeping getting "Resource XXX does not exist." exception while reviewing scala-search PR #68
was that ScalaSourceFile.createFromPath is NOT thread-safe
. This is obviously an issue since that method may be called concurrently by different threads.
The actual reason why `ScalaSourceFile.createFromPath` isn't thread-safe is because it relies on a cached HandleFactory instance
, which isn't thread-safe. It's so obvious that the current implementation of `ScalaSourceFile.createFromPath` is broken that I'm really surprised we have only found out about this now. I'm wondering now how many other bugs may have been a consequence of this incorrect implementation.
The simple fix is to create a fresh instance of `HandleFactory` for every call. However, this may decrease performances (the reason why `HandleFactory` isn't thread-safe is that it caches data for performance reasons). My current idea for fixing this is to create by default a fresh instance of `HandleFactory`, unless the caller explictly pass one (hence, the caller is responsible of ensuring correctnes, i.e., the passed `HandleFactory` instance is not shared across threads, unless a proper synchronization is in place).