Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEsteban Dugueperoux2014-11-03 17:26:00 +0000
committerEsteban Dugueperoux2015-02-02 08:31:02 +0000
commit8c711da1f172057cf2bf9c5695a47e083f63a303 (patch)
tree3f554313421180e81cfab675f08a49cb28c5e923 /plugins
parent4dc12f638545505831adcc63166feee8edffceec (diff)
downloadcdo-8c711da1f172057cf2bf9c5695a47e083f63a303.tar.gz
cdo-8c711da1f172057cf2bf9c5695a47e083f63a303.tar.xz
cdo-8c711da1f172057cf2bf9c5695a47e083f63a303.zip
[449806] NPE with CDOFetchRuleManager on CDOResource
Have a NPE when calling CDOView.getResource() will a CDOFetchRuleManager has been configured on the CDOSession. Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=449806 Change-Id: I3f6b44af78da7e9f05aa089b69f2475e80b6f9a6 Signed-off-by: Esteban Dugueperoux <esteban.dugueperoux@obeo.fr>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_449806_Test.java86
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java5
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java39
3 files changed, 112 insertions, 18 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_449806_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_449806_Test.java
new file mode 100644
index 0000000000..a22ce75d74
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_449806_Test.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2015 Obeo and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Esteban Dugueperoux - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.model1.Category;
+import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.view.CDOFetchRuleManager;
+import org.eclipse.emf.cdo.view.CDOView;
+
+import org.eclipse.emf.internal.cdo.analyzer.CDOAbstractFeatureRuleAnalyzer;
+import org.eclipse.emf.internal.cdo.analyzer.CDOFeatureAnalyzerModelBased;
+import org.eclipse.emf.internal.cdo.analyzer.CDOFeatureAnalyzerUI;
+import org.eclipse.emf.internal.cdo.session.CDOCollectionLoadingPolicyImpl;
+
+import org.eclipse.emf.spi.cdo.InternalCDOSession;
+
+/**
+ * Bug 449806 : Test {@link CDOFetchRuleManager} on {@link CDOResource}.
+ *
+ * @author Esteban Dugueperoux
+ */
+public class Bugzilla_449806_Test extends AbstractCDOTest
+{
+
+ private static final String RESOURCE_NAME = "test1.model1";
+
+ private static final int NB_CATEGORY = 10;
+
+ @Override
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ CDOSession session = openSession();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.getOrCreateResource(getResourcePath(RESOURCE_NAME));
+ Company company = getModel1Factory().createCompany();
+ for (int i = 0; i < NB_CATEGORY; i++)
+ {
+ Category category = getModel1Factory().createCategory();
+ company.getCategories().add(category);
+ }
+ resource.getContents().add(company);
+ transaction.commit();
+ transaction.close();
+ session.close();
+ }
+
+ public void testCDOFeatureAnalyzerUI() throws Exception
+ {
+ testCDOAbstractFeatureRuleAnalyzer(new CDOFeatureAnalyzerUI());
+ }
+
+ public void testCDOFeatureAnalyzerModelBased() throws Exception
+ {
+ testCDOAbstractFeatureRuleAnalyzer(new CDOFeatureAnalyzerModelBased());
+ }
+
+ private void testCDOAbstractFeatureRuleAnalyzer(CDOAbstractFeatureRuleAnalyzer abstractFeatureRuleAnalyzer)
+ throws Exception
+ {
+ CDOSession session = openSession();
+ session.options().setCollectionLoadingPolicy(new CDOCollectionLoadingPolicyImpl(1, 0));
+ ((InternalCDOSession)session).setFetchRuleManager(abstractFeatureRuleAnalyzer);
+
+ CDOView currentView = session.openView();
+ currentView.options().setFeatureAnalyzer(abstractFeatureRuleAnalyzer);
+
+ CDOResource resource = currentView.getResource(getResourcePath(RESOURCE_NAME));
+
+ Company company = (Company)resource.getContents().get(0);
+ assertEquals(NB_CATEGORY, company.getCategories().size());
+ }
+
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java
index 441168fa45..b5e6a6b230 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerModelBased.java
@@ -55,7 +55,10 @@ public class CDOFeatureAnalyzerModelBased extends CDOAbstractFeatureRuleAnalyzer
{
fetchData();
List<CDOFetchRule> rules = new ArrayList<CDOFetchRule>();
- rules.addAll(featureInfos.getRules(lastTraverseCDOObject.eClass(), lastTraverseFeature));
+ if (lastTraverseCDOObject != null)
+ {
+ rules.addAll(featureInfos.getRules(lastTraverseCDOObject.eClass(), lastTraverseFeature));
+ }
return rules;
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java
index b3d4d432b1..e676481a51 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/analyzer/CDOFeatureAnalyzerUI.java
@@ -73,28 +73,33 @@ public class CDOFeatureAnalyzerUI extends CDOAbstractFeatureRuleAnalyzer
public List<CDOFetchRule> getFetchRules(Collection<CDOID> ids)
{
- boolean addRootFeature = true;
- fetchData();
+ List<CDOFetchRule> list = new ArrayList<CDOFetchRule>();
- if (lastTraverseFeature.isMany())
+ boolean addRootFeature = true;
+ if (lastTraverseFeature != null)
{
- addRootFeature = false;
- }
+ fetchData();
- CDOClusterOfFetchRule search = new CDOClusterOfFetchRule(lastTraverseCDOObject.eClass(), lastTraverseFeature);
- CDOClusterOfFetchRule fetchOfRule = featureRules.get(search);
- if (fetchOfRule == null)
- {
- return null;
- }
+ if (lastTraverseFeature.isMany())
+ {
+ addRootFeature = false;
+ }
- Collection<CDOFetchRule> fetchRules = fetchOfRule.getFeatureInfo().getRules(null, null);
- List<CDOFetchRule> list = new ArrayList<CDOFetchRule>();
- for (CDOFetchRule fetchRule : fetchRules)
- {
- if (addRootFeature == true || lastTraverseCDOObject.eClass() != fetchRule.getEClass())
+ CDOClusterOfFetchRule search = new CDOClusterOfFetchRule(lastTraverseCDOObject.eClass(), lastTraverseFeature);
+ CDOClusterOfFetchRule fetchOfRule = featureRules.get(search);
+ if (fetchOfRule == null)
+ {
+ return null;
+ }
+
+ Collection<CDOFetchRule> fetchRules = fetchOfRule.getFeatureInfo().getRules(null, null);
+
+ for (CDOFetchRule fetchRule : fetchRules)
{
- list.add(fetchRule);
+ if (addRootFeature == true || lastTraverseCDOObject.eClass() != fetchRule.getEClass())
+ {
+ list.add(fetchRule);
+ }
}
}

Back to the top