ClassCastException on XMI import/export [message #820859] |
Wed, 14 March 2012 17:02 |
Simon Fremantle Messages: 4 Registered: March 2012 |
Junior Member |
|
|
I export EMF objects to and from XMI for persistence using XMLResource. Most of the time this works very well, but every now and then an error appears, such as the following examples:
mypackage.myclass1 cannot be cast to mypackage.myclass2 at mypackage.myclass3.getMyclass2
java.lang.String cannot be cast to java.util.List at mypackage.myclass2.eIsSet
java.lang.Object cannot be cast to java.util.List at mypackage.myclass2.eIsSet
I cannot see any pattern. Nor can I reproduce the problem.
I am using Galileo SR2, but cannot see a reference to this problem in any bug fixes since that date so doubt it is related to the EMF version.
However, the EMF objects are used in a Web application, which is highly concurrent, so I wonder if the XMLResource load/save options I am using are unsuitable. I based them on EMFPerformanceTips.html from eclipse.org - see below for my code.
Could one of these options be causing the problem? Any advice gratefully received!
Simon
// Resource load and save options
private static final Map resourceLoadOptions = new HashMap();
private static final Map resourceSaveOptions = new HashMap();
private static final XMLParserPool xmlParserPool = new XMLParserPoolImpl();
private static final Map nameToFeatureMap = new HashMap();
private static final List lookupTable = new ArrayList();
// Initialize load and save options
static {
resourceLoadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION,
Boolean.TRUE);
resourceLoadOptions.put(XMLResource.OPTION_USE_PARSER_POOL,
xmlParserPool);
resourceLoadOptions.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP,
nameToFeatureMap);
resourceSaveOptions.put(XMLResource.OPTION_ENCODING, XML_ENCODING);
resourceSaveOptions.put(XMLResource.OPTION_USE_CACHED_LOOKUP_TABLE,
lookupTable);
resourceSaveOptions.put(XMLResource.OPTION_CONFIGURATION_CACHE,
Boolean.TRUE);
resourceSaveOptions.put(XMLResource.OPTION_FORMATTED, Boolean.FALSE);
}
|
|
|
Re: ClassCastException on XMI import/export [message #821241 is a reply to message #820859] |
Thu, 15 March 2012 04:53 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Simon,
The nameToFeatureMap and the lookup table in lookupTable are used to
cache information computed about the model so they can be updated while
parsing (for the former) and while saving (for the latter). You could
use thread local instances to avoid sharing them across threads. It
appears you're setting them up in some static singleton way but of
course a thread local solution would require you to set up these
particular options on the thread on which you save or load. You could
do it in the factory if the thread on which you create the resource is
also the one where you load and save.
On 14/03/2012 6:02 PM, Simon Fremantle wrote:
> I export EMF objects to and from XMI for persistence using
> XMLResource. Most of the time this works very well, but every now and
> then an error appears, such as the following examples:
>
> mypackage.myclass1 cannot be cast to mypackage.myclass2 at
> mypackage.myclass3.getMyclass2
>
> java.lang.String cannot be cast to java.util.List at
> mypackage.myclass2.eIsSet
>
> java.lang.Object cannot be cast to java.util.List at
> mypackage.myclass2.eIsSet
>
> I cannot see any pattern. Nor can I reproduce the problem.
>
> I am using Galileo SR2, but cannot see a reference to this problem in
> any bug fixes since that date so doubt it is related to the EMF version.
>
> However, the EMF objects are used in a Web application, which is
> highly concurrent, so I wonder if the XMLResource load/save options I
> am using are unsuitable. I based them on EMFPerformanceTips.html from
> eclipse.org - see below for my code.
>
> Could one of these options be causing the problem? Any advice
> gratefully received!
>
> Simon
>
> // Resource load and save options
> private static final Map resourceLoadOptions = new HashMap();
> private static final Map resourceSaveOptions = new HashMap();
> private static final XMLParserPool xmlParserPool = new
> XMLParserPoolImpl();
> private static final Map nameToFeatureMap = new HashMap();
> private static final List lookupTable = new ArrayList();
>
> // Initialize load and save options
> static {
>
> resourceLoadOptions.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION,
> Boolean.TRUE);
> resourceLoadOptions.put(XMLResource.OPTION_USE_PARSER_POOL,
> xmlParserPool);
> resourceLoadOptions.put(XMLResource.OPTION_USE_XML_NAME_TO_FEATURE_MAP,
>
> nameToFeatureMap);
>
> resourceSaveOptions.put(XMLResource.OPTION_ENCODING,
> XML_ENCODING);
>
> resourceSaveOptions.put(XMLResource.OPTION_USE_CACHED_LOOKUP_TABLE,
> lookupTable);
> resourceSaveOptions.put(XMLResource.OPTION_CONFIGURATION_CACHE,
> Boolean.TRUE);
> resourceSaveOptions.put(XMLResource.OPTION_FORMATTED,
> Boolean.FALSE);
> }
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03962 seconds