Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 407539

Summary: EList.add used to throw IllegalArgumentException, now throws ArrayStoreException
Product: [Modeling] EMF Reporter: Paul Elder <pelder.eclipse>
Component: CoreAssignee: Ed Merks <Ed.Merks>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 2.9.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Paul Elder CLA 2013-05-08 10:31:43 EDT
This arises from regenerating the Eclipse UI model with 2.9.0.v20130318-0639. A Platform UI JUnit that verifies that a type-erased EList throws IllegalArgumentException when an incompatible type is added to the list.

With the regenerated code, the list now throws ArrayStoreException. 

The javadoc for EList.add(Object) states that it throws:
ClassCastException - when the class of the object is inappropriate for this List
IllegalArgumentException - when the object cannot be added to this List

So, it seems that neither the old nor the new behavior is compatible with the declared contract.

The test case may be found here (testAddingInvalidElements):

https://git.eclipse.org/c/platform/eclipse.platform.ui.git/tree/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/application/ModelRobustnessTest.java
Comment 1 Ed Merks CLA 2013-05-09 01:28:42 EDT
Sorry, but I don't intend to change this behavior; it's always been this way.  The exception comes from the typed array and the performance of allowing the array to do the type checking outweighs any benefit from adding additional logic to throw a different exception.
Comment 2 Paul Elder CLA 2013-05-09 16:41:10 EDT
Thanks Ed. I've changed the platform UI unit test to accept ArrayStoreException as well as IllegalArgumentException.