Skip to content

Commit 37fcdbf

Browse files
committed
eol.engine: fix CachedResourceSet release if model fails to save (fixes #181)
1 parent 53c995f commit 37fcdbf

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

plugins/org.eclipse.epsilon.eol.engine/src/org/eclipse/epsilon/eol/models/CachedModel.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,12 @@ public void load(StringProperties properties, IRelativePathResolver resolver) th
307307

308308
@Override
309309
public void dispose() {
310-
super.dispose();
311-
clearCache();
312-
disposeModel();
310+
try {
311+
super.dispose();
312+
} finally {
313+
clearCache();
314+
disposeModel();
315+
}
313316
}
314317

315318
public void clearCache() {

tests/org.eclipse.epsilon.emc.emf.test/src/org/eclipse/epsilon/emc/emf/CachedResourceSetTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import org.eclipse.emf.common.util.URI;
2020
import org.eclipse.emf.ecore.EcorePackage;
21+
import org.eclipse.emf.ecore.resource.Resource;
22+
import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;
2123
import org.junit.After;
2224
import org.junit.Before;
2325
import org.junit.Test;
@@ -76,6 +78,30 @@ public void testDisposeBadModel() throws Exception {
7678
0, CachedResourceSet.getCache().size());
7779
}
7880

81+
@SuppressWarnings("resource")
82+
@Test
83+
public void testDisposeFailedSave() throws Exception {
84+
// Register a file extension whose saves will always fail
85+
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("brokensave", new ResourceFactoryImpl());
86+
87+
EmfModel model = new EmfModel();
88+
model.setModelFileUri(URI.createFileURI(new File("f.brokensave").getAbsolutePath()));
89+
model.setMetamodelUri(EcorePackage.eNS_URI);
90+
model.setReadOnLoad(false);
91+
model.setStoredOnDisposal(true);
92+
model.load();
93+
94+
try {
95+
model.dispose();
96+
fail("Saving the model should have failed");
97+
} catch (Exception ex) {
98+
// do nothing - this is expected
99+
}
100+
101+
assertEquals("Disposing a model which failed to save should result in an empty cache",
102+
0, CachedResourceSet.getCache().size());
103+
}
104+
79105
@Test
80106
public void testGc() throws Exception {
81107
model1.load();

0 commit comments

Comments
 (0)