protected final GradleProjectPlatformQuery trySetQuery(GradleProjectPlatformQuery query) {
ExceptionHelper.checkNotNullArgument(query, "query");
if (queryRef.compareAndSet(null, query)) {
ListenerRef toRemove = null;
InitLaterListenerRef toAdd = null;
changesLock.lock();
try {
if (changes.hasListeners()) {
toRemove = subListenerRef;
toAdd = new InitLaterListenerRef();
subListenerRef = toAdd;
}
} finally {
changesLock.unlock();
}
if (toRemove != null) {
toRemove.unregister();
}
if (toAdd != null) {
toAdd.init(query.addPlatformChangeListener(new Runnable() {
@Override
public void run() {
firePlatformChange();
}
}));