WID tips: when a Horse is not a Horse

This confusing error message might appear any time you use EMF (Eclipse Modeling Framework), but is especially frequent in WID when developing SCA modules. How would you like this puzzle:
java.lang.ClassCastException: The feature 'fooBar's type 'FooBar' does not permit a value of type 'FooBar'

One typical situation when this error occurs is when serialization of DataObject of declared type FooBar fails because the instance of DataObject in question is not valid. In other words, if the DataObject was serialized into XML, the XML would be invalid according to it’s XSD. For example you might have declared that it is a Horse but forgot to create any Legs. Thus my troubleshooting recommendation for this error message is to inspect DataObject in question and validate it against it’s schema.

A DataObject may be created in several ways, such as implicitly as BO Map output or explicitly by Java API. Immediately upon creation the DataObject is empty, which means it is quite likely not valid (unless you have a very lax schema where everything is optional). Next, your BO Map or Java component runs to completion. SCA runtime does not validate your DataObject at that time. This is good: you do not have to set all fields of the DataObject at the same time. Maybe you do not have all required information yet – it will be collected later in your flow. Interestingly, validation will not occur when message containing the DataObject crosses module boundary. This is true even if your message is apparently serialized – in a JMS binding with “Business Object XML” data binding. This means that invalid object may travel great distances without being discovered, which does not simplify your troubleshooting.

Advertisements

Comments are closed.

%d bloggers like this: