f2dee2bf85
getOrCreateApplicationEnvironment is main entrypoint to create ApplicationEnvironment in production and compiler tests It is subject to be called concurrently, that's why APPLICATION_LOCK exists ApplicationEnvironment itself hosts Application from idea-core It is actually singleton, that is subject to be disposed, once all operations referencing it completes To properly dispose ApplicationEnvironment when there is no references left, we maintain reference counter aka ourProjectCount Originally, there was data-race caused by the fact, that ourProjectCount was updated after publication of application Linear, data-race occurs in following order T1: getOrCreateApplicationEnvironment returns application T2: Disposes its reference to application, causing ourProjectCount to reach zero, and disposing application that is already available to T1 T1: Updates counter, but its application already disposed