Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-01-26 04:46:29 -0500
committerEike Stepper2013-01-26 04:46:29 -0500
commit1c4e7ab26dedb80718f2ac30f804198b4fa7e8cf (patch)
tree04d0df55aa8b64733f08f3e07911de84bdf51af3
parent95b519d19181f4f7c65eb50fd7517a3e79feab1c (diff)
downloadcdo-1c4e7ab26dedb80718f2ac30f804198b4fa7e8cf.tar.gz
cdo-1c4e7ab26dedb80718f2ac30f804198b4fa7e8cf.tar.xz
cdo-1c4e7ab26dedb80718f2ac30f804198b4fa7e8cf.zip
[399155] Resource and XRef queries are not robust against closed views
https://bugs.eclipse.org/bugs/show_bug.cgi?id=399155
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java30
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java10
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java11
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java30
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreThreadLocal.java20
-rw-r--r--plugins/org.eclipse.emf.cdo.ui.ide/src/org/eclipse/emf/cdo/ui/internal/ide/actions/TransactionalBackgroundActionDelegate.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java17
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java5
8 files changed, 82 insertions, 43 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java
index 830279b00b..8b95f43245 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java
@@ -19,6 +19,7 @@ import org.eclipse.emf.cdo.server.IQueryContext;
import org.eclipse.emf.cdo.server.IQueryHandler;
import org.eclipse.emf.cdo.server.IStoreAccessor;
import org.eclipse.emf.cdo.server.StoreThreadLocal;
+import org.eclipse.emf.cdo.server.StoreThreadLocal.NoSessionRegisteredException;
import org.eclipse.emf.cdo.spi.server.QueryHandlerFactory;
import org.eclipse.net4j.util.factory.ProductCreationException;
@@ -38,19 +39,26 @@ public class ResourcesQueryHandler implements IQueryHandler
public void executeQuery(CDOQueryInfo info, IQueryContext context)
{
- IStoreAccessor accessor = StoreThreadLocal.getAccessor();
- QueryContext resourcesContext = new QueryContext(info, context);
- accessor.queryResources(resourcesContext);
-
- CDOBranchPoint branchPoint = context;
- CDOBranch branch = branchPoint.getBranch();
- while (!branch.isMainBranch() && resourcesContext.getResourceIDs().size() < info.getMaxResults())
+ try
{
- branchPoint = branch.getBase();
- branch = branchPoint.getBranch();
-
- resourcesContext.setBranchPoint(branchPoint);
+ IStoreAccessor accessor = StoreThreadLocal.getAccessor();
+ QueryContext resourcesContext = new QueryContext(info, context);
accessor.queryResources(resourcesContext);
+
+ CDOBranchPoint branchPoint = context;
+ CDOBranch branch = branchPoint.getBranch();
+ while (!branch.isMainBranch() && resourcesContext.getResourceIDs().size() < info.getMaxResults())
+ {
+ branchPoint = branch.getBase();
+ branch = branchPoint.getBranch();
+
+ resourcesContext.setBranchPoint(branchPoint);
+ accessor.queryResources(resourcesContext);
+ }
+ }
+ catch (NoSessionRegisteredException ex)
+ {
+ // View has been closed - do nothing
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java
index f449e3d50c..8630b5f4f4 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Transaction.java
@@ -53,7 +53,7 @@ public class Transaction extends View implements InternalTransaction
/**
* For tests only.
- *
+ *
* @since 2.0
*/
public InternalCommitContext testCreateCommitContext(final long timeStamp)
@@ -77,12 +77,4 @@ public class Transaction extends View implements InternalTransaction
throw new IllegalArgumentException("Changing the target time is not supported by transactions");
}
}
-
- private void checkOpen()
- {
- if (isClosed())
- {
- throw new IllegalStateException("View closed"); //$NON-NLS-1$
- }
- }
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java
index 8008684d57..dfce5c91bc 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java
@@ -57,6 +57,8 @@ public class View extends Lifecycle implements InternalView, CDOCommonView.Optio
private boolean lockNotificationsEnabled;
+ private boolean closed;
+
/**
* @since 2.0
*/
@@ -115,7 +117,6 @@ public class View extends Lifecycle implements InternalView, CDOCommonView.Optio
*/
public InternalRepository getRepository()
{
- checkOpen();
return repository;
}
@@ -265,9 +266,7 @@ public class View extends Lifecycle implements InternalView, CDOCommonView.Optio
public void doClose()
{
clearChangeSubscription();
- changeSubscriptionIDs = null;
- session = null;
- repository = null;
+ closed = true;
}
/**
@@ -275,10 +274,10 @@ public class View extends Lifecycle implements InternalView, CDOCommonView.Optio
*/
public boolean isClosed()
{
- return repository == null;
+ return closed;
}
- private void checkOpen()
+ protected void checkOpen()
{
if (isClosed())
{
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java
index fac589ad6a..619180eb48 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/XRefsQueryHandler.java
@@ -31,6 +31,7 @@ import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.IStoreAccessor;
import org.eclipse.emf.cdo.server.IView;
import org.eclipse.emf.cdo.server.StoreThreadLocal;
+import org.eclipse.emf.cdo.server.StoreThreadLocal.NoSessionRegisteredException;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.emf.cdo.spi.server.QueryHandlerFactory;
@@ -61,19 +62,26 @@ public class XRefsQueryHandler implements IQueryHandler
public void executeQuery(CDOQueryInfo info, IQueryContext context)
{
- IStoreAccessor accessor = StoreThreadLocal.getAccessor();
- QueryContext xrefsContext = new QueryContext(info, context);
- accessor.queryXRefs(xrefsContext);
-
- CDOBranchPoint branchPoint = context;
- CDOBranch branch = branchPoint.getBranch();
- while (!branch.isMainBranch() && context.getResultCount() < info.getMaxResults())
+ try
{
- branchPoint = branch.getBase();
- branch = branchPoint.getBranch();
-
- xrefsContext.setBranchPoint(branchPoint);
+ IStoreAccessor accessor = StoreThreadLocal.getAccessor();
+ QueryContext xrefsContext = new QueryContext(info, context);
accessor.queryXRefs(xrefsContext);
+
+ CDOBranchPoint branchPoint = context;
+ CDOBranch branch = branchPoint.getBranch();
+ while (!branch.isMainBranch() && context.getResultCount() < info.getMaxResults())
+ {
+ branchPoint = branch.getBase();
+ branch = branchPoint.getBranch();
+
+ xrefsContext.setBranchPoint(branchPoint);
+ accessor.queryXRefs(xrefsContext);
+ }
+ }
+ catch (NoSessionRegisteredException ex)
+ {
+ // View has been closed - do nothing
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreThreadLocal.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreThreadLocal.java
index a80f29646c..21c5e40f36 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreThreadLocal.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreThreadLocal.java
@@ -54,12 +54,12 @@ public final class StoreThreadLocal
* if no session is associated with the current thread.
* @since 3.0
*/
- public static InternalSession getSession()
+ public static InternalSession getSession() throws NoSessionRegisteredException
{
InternalSession session = SESSION.get();
if (session == null)
{
- throw new IllegalStateException("session == null"); //$NON-NLS-1$
+ throw new NoSessionRegisteredException();
}
return session;
@@ -79,7 +79,7 @@ public final class StoreThreadLocal
ACCESSOR.set(accessor);
}
- public static IStoreAccessor getAccessor()
+ public static IStoreAccessor getAccessor() throws NoSessionRegisteredException
{
IStoreAccessor accessor = ACCESSOR.get();
if (accessor == null)
@@ -126,4 +126,18 @@ public final class StoreThreadLocal
COMMIT_CONTEXT.remove();
}
}
+
+ /**
+ * @author Eike Stepper
+ * @since 4.2
+ */
+ public static final class NoSessionRegisteredException extends IllegalStateException
+ {
+ private static final long serialVersionUID = 1L;
+
+ public NoSessionRegisteredException()
+ {
+ super("session == null");
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.ui.ide/src/org/eclipse/emf/cdo/ui/internal/ide/actions/TransactionalBackgroundActionDelegate.java b/plugins/org.eclipse.emf.cdo.ui.ide/src/org/eclipse/emf/cdo/ui/internal/ide/actions/TransactionalBackgroundActionDelegate.java
index e88a81a521..019b505c44 100644
--- a/plugins/org.eclipse.emf.cdo.ui.ide/src/org/eclipse/emf/cdo/ui/internal/ide/actions/TransactionalBackgroundActionDelegate.java
+++ b/plugins/org.eclipse.emf.cdo.ui.ide/src/org/eclipse/emf/cdo/ui/internal/ide/actions/TransactionalBackgroundActionDelegate.java
@@ -79,7 +79,7 @@ public abstract class TransactionalBackgroundActionDelegate extends LongRunningA
if (transactionalObject != null)
{
CDOView view = transactionalObject.cdoView();
- if (!(view instanceof CDOTransaction))
+ if (view.isReadOnly())
{
throw new IllegalStateException(MessageFormat.format(
Messages.getString("TransactionalBackgroundAction_0"), transactionalObject)); //$NON-NLS-1$
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
index 8177e08a53..4277fe2b2d 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
@@ -1504,8 +1504,21 @@ public class CDOResourceImpl extends CDOResourceLeafImpl implements InternalCDOR
Pair<CDOView, CDOViewProvider> pair = CDOViewProviderRegistry.INSTANCE.provideViewWithInfo(uri, resourceSet);
if (pair != null)
{
- view = (InternalCDOView)pair.getElement1();
- view.attachResource(this);
+ try
+ {
+ view = (InternalCDOView)pair.getElement1();
+ view.attachResource(this);
+ }
+ catch (RuntimeException ex)
+ {
+ resourceSet.getResources().remove(this);
+ throw ex;
+ }
+ catch (Error ex)
+ {
+ resourceSet.getResources().remove(this);
+ throw ex;
+ }
viewProvider = pair.getElement2();
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
index 3bdeca3e98..c9a7840a00 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java
@@ -77,6 +77,7 @@ import org.eclipse.net4j.util.container.IContainerDelta;
import org.eclipse.net4j.util.container.IContainerEvent;
import org.eclipse.net4j.util.container.SingleDeltaContainerEvent;
import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.lifecycle.LifecycleException;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.log.OMLogger;
import org.eclipse.net4j.util.om.trace.ContextTracer;
@@ -1281,6 +1282,10 @@ public abstract class AbstractCDOView extends CDOCommitHistoryProviderImpl<CDOOb
rootResource = resource;
}
}
+ catch (LifecycleException ex)
+ {
+ throw ex;
+ }
catch (Exception ex)
{
throw new InvalidURIException(uri, ex);

Back to the top