Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEsteban Dugueperoux2013-07-10 13:29:38 +0000
committerEike Stepper2013-08-07 10:33:23 +0000
commitd4e32cc5f4c52db8c180441a147dd25690d036c3 (patch)
tree0466389ad081bf19d0b2887aa75fe83eff3b8017 /plugins/org.eclipse.emf.cdo
parent3b6576570a80ea1da099550451e47e8b0b5256d3 (diff)
downloadcdo-d4e32cc5f4c52db8c180441a147dd25690d036c3.tar.gz
cdo-d4e32cc5f4c52db8c180441a147dd25690d036c3.tar.xz
cdo-d4e32cc5f4c52db8c180441a147dd25690d036c3.zip
[412686] NPE when removing/adding an adapter after CDO view closed
https://bugs.eclipse.org/bugs/show_bug.cgi?id=412686 Change-Id: Iaf809222d20f1bcb858e3e92c2d5ef17b452d25c
Diffstat (limited to 'plugins/org.eclipse.emf.cdo')
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java8
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/AbstractCDOView.java80
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java110
3 files changed, 128 insertions, 70 deletions
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
index 2197cdc07f..8561e2b651 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/transaction/CDOTransactionImpl.java
@@ -3230,6 +3230,8 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
public void setConflictResolvers(CDOConflictResolver[] resolvers)
{
+ checkActive();
+
synchronized (CDOTransactionImpl.this)
{
for (CDOConflictResolver resolver : conflictResolvers)
@@ -3251,6 +3253,8 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
public void addConflictResolver(CDOConflictResolver resolver)
{
+ checkActive();
+
IEvent event = null;
synchronized (CDOTransactionImpl.this)
{
@@ -3264,6 +3268,8 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
public void removeConflictResolver(CDOConflictResolver resolver)
{
+ checkActive();
+
IEvent event = null;
synchronized (CDOTransactionImpl.this)
{
@@ -3316,6 +3322,8 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
public void setAutoReleaseLocksEnabled(boolean on)
{
+ checkActive();
+
IEvent event = null;
synchronized (CDOTransactionImpl.this)
{
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 52be98558d..44169b5081 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
@@ -83,6 +83,9 @@ 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;
+import org.eclipse.net4j.util.ref.KeyedReference;
+import org.eclipse.net4j.util.ref.ReferenceType;
+import org.eclipse.net4j.util.ref.ReferenceValueMap2;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
@@ -112,6 +115,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
/**
@@ -157,10 +161,12 @@ public abstract class AbstractCDOView extends CDOCommitHistoryProviderImpl<CDOOb
public AbstractCDOView(CDOBranchPoint branchPoint)
{
basicSetBranchPoint(branchPoint);
+ initObjectsMap(ReferenceType.SOFT);
}
public AbstractCDOView()
{
+ initObjectsMap(ReferenceType.SOFT);
}
public boolean isReadOnly()
@@ -194,6 +200,75 @@ public abstract class AbstractCDOView extends CDOCommitHistoryProviderImpl<CDOOb
this.objects = objects;
}
+ protected boolean initObjectsMap(ReferenceType referenceType)
+ {
+ ReferenceValueMap2<CDOID, InternalCDOObject> newObjects;
+
+ switch (referenceType)
+ {
+ case STRONG:
+ {
+ if (objects instanceof ReferenceValueMap2.Strong<?, ?>)
+ {
+ return false;
+ }
+
+ Map<CDOID, KeyedReference<CDOID, InternalCDOObject>> map = CDOIDUtil.createMap();
+ newObjects = new ReferenceValueMap2.Strong<CDOID, InternalCDOObject>(map);
+ break;
+ }
+
+ case SOFT:
+ {
+ if (objects instanceof ReferenceValueMap2.Soft<?, ?>)
+ {
+ return false;
+ }
+
+ Map<CDOID, KeyedReference<CDOID, InternalCDOObject>> map = CDOIDUtil.createMap();
+ newObjects = new ReferenceValueMap2.Soft<CDOID, InternalCDOObject>(map);
+ break;
+ }
+
+ case WEAK:
+ {
+ if (objects instanceof ReferenceValueMap2.Weak<?, ?>)
+ {
+ return false;
+ }
+
+ Map<CDOID, KeyedReference<CDOID, InternalCDOObject>> map = CDOIDUtil.createMap();
+ newObjects = new ReferenceValueMap2.Weak<CDOID, InternalCDOObject>(map);
+ break;
+ }
+
+ default:
+ throw new IllegalArgumentException(Messages.getString("CDOViewImpl.29")); //$NON-NLS-1$
+ }
+
+ if (objects == null)
+ {
+ setObjects(newObjects);
+ }
+ else
+ {
+ for (Entry<CDOID, InternalCDOObject> entry : objects.entrySet())
+ {
+ InternalCDOObject object = entry.getValue();
+ if (object != null)
+ {
+ newObjects.put(entry.getKey(), object);
+ }
+ }
+
+ Map<CDOID, InternalCDOObject> oldObjects = objects;
+ setObjects(newObjects);
+ oldObjects.clear();
+ }
+
+ return true;
+ }
+
public ViewAndState getViewAndState(CDOState state)
{
return viewAndStates[state.ordinal()];
@@ -1542,6 +1617,11 @@ public abstract class AbstractCDOView extends CDOCommitHistoryProviderImpl<CDOOb
@Override
public String toString()
{
+ if (!isActive())
+ {
+ return super.toString();
+ }
+
StringBuilder builder = new StringBuilder();
if (isReadOnly())
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
index 0bafbc8e1c..02c5991ca6 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/view/CDOViewImpl.java
@@ -76,10 +76,8 @@ import org.eclipse.net4j.util.om.monitor.EclipseMonitor;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.options.OptionsEvent;
-import org.eclipse.net4j.util.ref.KeyedReference;
import org.eclipse.net4j.util.ref.ReferenceType;
import org.eclipse.net4j.util.ref.ReferenceValueMap;
-import org.eclipse.net4j.util.ref.ReferenceValueMap2;
import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.NotificationChain;
@@ -106,7 +104,6 @@ import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Set;
import java.util.WeakHashMap;
@@ -1105,7 +1102,10 @@ public class CDOViewImpl extends AbstractCDOView
*/
public synchronized void subscribe(EObject eObject, Adapter adapter)
{
- changeSubscriptionManager.subscribe(eObject, adapter);
+ if (changeSubscriptionManager != null)
+ {
+ changeSubscriptionManager.subscribe(eObject, adapter);
+ }
}
/**
@@ -1113,7 +1113,10 @@ public class CDOViewImpl extends AbstractCDOView
*/
public synchronized void unsubscribe(EObject eObject, Adapter adapter)
{
- changeSubscriptionManager.unsubscribe(eObject, adapter);
+ if (changeSubscriptionManager != null)
+ {
+ changeSubscriptionManager.unsubscribe(eObject, adapter);
+ }
}
/**
@@ -1121,7 +1124,12 @@ public class CDOViewImpl extends AbstractCDOView
*/
public synchronized boolean hasSubscription(CDOID id)
{
- return changeSubscriptionManager.getSubcribeObject(id) != null;
+ if (changeSubscriptionManager != null)
+ {
+ return changeSubscriptionManager.getSubcribeObject(id) != null;
+ }
+
+ return false;
}
/**
@@ -1239,7 +1247,6 @@ public class CDOViewImpl extends AbstractCDOView
}
changeSubscriptionManager = null;
- options = null;
super.doDeactivate();
}
@@ -1790,7 +1797,6 @@ public class CDOViewImpl extends AbstractCDOView
public OptionsImpl()
{
- setCacheReferenceType(null);
}
public CDOViewImpl getContainer()
@@ -1808,6 +1814,8 @@ public class CDOViewImpl extends AbstractCDOView
public void setLoadNotificationEnabled(boolean enabled)
{
+ checkActive();
+
IEvent event = null;
synchronized (CDOViewImpl.this)
{
@@ -1831,6 +1839,8 @@ public class CDOViewImpl extends AbstractCDOView
public void setDetachmentNotificationEnabled(boolean enabled)
{
+ checkActive();
+
IEvent event = null;
synchronized (CDOViewImpl.this)
{
@@ -1854,6 +1864,8 @@ public class CDOViewImpl extends AbstractCDOView
public void setInvalidationNotificationEnabled(boolean enabled)
{
+ checkActive();
+
IEvent event = null;
synchronized (CDOViewImpl.this)
{
@@ -1877,6 +1889,8 @@ public class CDOViewImpl extends AbstractCDOView
public void setInvalidationPolicy(CDOInvalidationPolicy policy)
{
+ checkActive();
+
IEvent event = null;
synchronized (CDOViewImpl.this)
{
@@ -1897,6 +1911,8 @@ public class CDOViewImpl extends AbstractCDOView
public void setLockNotificationEnabled(boolean enabled)
{
+ checkActive();
+
IEvent event = null;
synchronized (CDOViewImpl.this)
{
@@ -1930,6 +1946,8 @@ public class CDOViewImpl extends AbstractCDOView
public void addChangeSubscriptionPolicy(CDOAdapterPolicy policy)
{
+ checkActive();
+
IEvent event = null;
synchronized (CDOViewImpl.this)
{
@@ -1945,6 +1963,8 @@ public class CDOViewImpl extends AbstractCDOView
public void removeChangeSubscriptionPolicy(CDOAdapterPolicy policy)
{
+ checkActive();
+
IEvent event = null;
synchronized (CDOViewImpl.this)
{
@@ -1968,6 +1988,8 @@ public class CDOViewImpl extends AbstractCDOView
public void setStrongReferencePolicy(CDOAdapterPolicy adapterPolicy)
{
+ checkActive();
+
if (adapterPolicy == null)
{
adapterPolicy = CDOAdapterPolicy.ALL;
@@ -1997,6 +2019,8 @@ public class CDOViewImpl extends AbstractCDOView
public void setRevisionPrefetchingPolicy(CDORevisionPrefetchingPolicy prefetchingPolicy)
{
+ checkActive();
+
if (prefetchingPolicy == null)
{
prefetchingPolicy = CDORevisionPrefetchingPolicy.NO_PREFETCHING;
@@ -2025,6 +2049,8 @@ public class CDOViewImpl extends AbstractCDOView
public void setFeatureAnalyzer(CDOFeatureAnalyzer featureAnalyzer)
{
+ checkActive();
+
if (featureAnalyzer == null)
{
featureAnalyzer = CDOFeatureAnalyzer.NOOP;
@@ -2065,6 +2091,8 @@ public class CDOViewImpl extends AbstractCDOView
public void setStaleReferencePolicy(CDOStaleReferencePolicy policy)
{
+ checkActive();
+
if (policy == null)
{
policy = CDOStaleReferencePolicy.DEFAULT;
@@ -2109,6 +2137,8 @@ public class CDOViewImpl extends AbstractCDOView
public boolean setCacheReferenceType(ReferenceType referenceType)
{
+ checkActive();
+
if (referenceType == null)
{
referenceType = ReferenceType.SOFT;
@@ -2116,69 +2146,9 @@ public class CDOViewImpl extends AbstractCDOView
synchronized (CDOViewImpl.this)
{
- Map<CDOID, InternalCDOObject> objects = getModifiableObjects();
- ReferenceValueMap2<CDOID, InternalCDOObject> newObjects;
-
- switch (referenceType)
- {
- case STRONG:
- {
- if (objects instanceof ReferenceValueMap2.Strong<?, ?>)
- {
- return false;
- }
-
- Map<CDOID, KeyedReference<CDOID, InternalCDOObject>> map = CDOIDUtil.createMap();
- newObjects = new ReferenceValueMap2.Strong<CDOID, InternalCDOObject>(map);
- break;
- }
-
- case SOFT:
- {
- if (objects instanceof ReferenceValueMap2.Soft<?, ?>)
- {
- return false;
- }
-
- Map<CDOID, KeyedReference<CDOID, InternalCDOObject>> map = CDOIDUtil.createMap();
- newObjects = new ReferenceValueMap2.Soft<CDOID, InternalCDOObject>(map);
- break;
- }
-
- case WEAK:
- {
- if (objects instanceof ReferenceValueMap2.Weak<?, ?>)
- {
- return false;
- }
-
- Map<CDOID, KeyedReference<CDOID, InternalCDOObject>> map = CDOIDUtil.createMap();
- newObjects = new ReferenceValueMap2.Weak<CDOID, InternalCDOObject>(map);
- break;
- }
-
- default:
- throw new IllegalArgumentException(Messages.getString("CDOViewImpl.29")); //$NON-NLS-1$
- }
-
- if (objects == null)
- {
- setObjects(newObjects);
- }
- else
+ if (!initObjectsMap(referenceType))
{
- for (Entry<CDOID, InternalCDOObject> entry : objects.entrySet())
- {
- InternalCDOObject object = entry.getValue();
- if (object != null)
- {
- newObjects.put(entry.getKey(), object);
- }
- }
-
- Map<CDOID, InternalCDOObject> oldObjects = objects;
- setObjects(newObjects);
- oldObjects.clear();
+ return false;
}
}

Back to the top