diff options
-rw-r--r-- | plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/Diagnostician.java | 2 | ||||
-rw-r--r-- | tests/org.eclipse.emf.test.core/src/org/eclipse/emf/test/core/ecore/DiagnosticianTest.java | 50 |
2 files changed, 49 insertions, 3 deletions
diff --git a/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/Diagnostician.java b/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/Diagnostician.java index 6d07adf39..7c6b081b5 100644 --- a/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/Diagnostician.java +++ b/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/util/Diagnostician.java @@ -277,7 +277,7 @@ public class Diagnostician implements EValidator.SubstitutionLabelProvider, EVal */ protected boolean handleThrowable(EClass eClass, EObject eObject, DiagnosticChain diagnostics, Map<Object, Object> context, Throwable throwable) { - if (diagnostics != null && throwable instanceof RuntimeException || throwable instanceof AssertionError) + if (diagnostics != null && (throwable instanceof RuntimeException || throwable instanceof AssertionError)) { Object[] messageSubstitutions = new Object []{ EObjectValidator.getObjectLabel(eObject, context) }; String message = EcorePlugin.INSTANCE.getString("_UI_ValidationFailed_diagnostic", messageSubstitutions); diff --git a/tests/org.eclipse.emf.test.core/src/org/eclipse/emf/test/core/ecore/DiagnosticianTest.java b/tests/org.eclipse.emf.test.core/src/org/eclipse/emf/test/core/ecore/DiagnosticianTest.java index f6fdcb885..ae2bfe3c7 100644 --- a/tests/org.eclipse.emf.test.core/src/org/eclipse/emf/test/core/ecore/DiagnosticianTest.java +++ b/tests/org.eclipse.emf.test.core/src/org/eclipse/emf/test/core/ecore/DiagnosticianTest.java @@ -278,7 +278,7 @@ public class DiagnosticianTest } @Test - public void testExceptionHandlingRecorded() + public void testExceptionHandlingRecordedNPE() { final NullPointerException exception = new NullPointerException(); EClass eClass = new EClassImpl() @@ -299,7 +299,28 @@ public class DiagnosticianTest } @Test - public void testExceptionHandlingNotRecorded() + public void testExceptionHandlingRecordedAE() + { + final AssertionError exception = new AssertionError(); + EClass eClass = new EClassImpl() + { + @Override + public EList<EClass> getEAllSuperTypes() + { + throw exception; + } + }; + + Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eClass); + Assert.assertEquals("Expected an error", Diagnostic.ERROR, diagnostic.getSeverity()); + Assert.assertEquals("Expected one child", 1, diagnostic.getChildren().size()); + Diagnostic child = diagnostic.getChildren().get(0); + Throwable diagnosticException = child.getException(); + Assert.assertSame("Expected the specific exception to be thrown", exception, diagnosticException); + } + + @Test + public void testExceptionHandlingNotRecordedNPE() { final NullPointerException exception = new NullPointerException(); EClass eClass = new EClassImpl() @@ -322,6 +343,31 @@ public class DiagnosticianTest Assert.assertSame("Expected the specific exception to be thrown", exception, throwable); } } + + @Test + public void testExceptionHandlingNotRecordedAE() + { + final AssertionError exception = new AssertionError(); + EClass eClass = new EClassImpl() + { + @Override + public EList<EClass> getEAllSuperTypes() + { + throw exception; + } + }; + + try + { + @SuppressWarnings("unused") + boolean isValid = Diagnostician.INSTANCE.validate(eClass, (DiagnosticChain)null); + Assert.fail("Exected an exception to be thrown"); + } + catch (Throwable throwable) + { + Assert.assertSame("Expected the specific exception to be thrown", exception, throwable); + } + } @Test public void testExceptionHandlingNotHandledException() |