Problem with Features of Type Class [message #1855268] |
Wed, 05 October 2022 08:09  |
Eclipse User |
|
|
|
Hello,
When using the type "Class" (any Java class) for a feature in an ECore Model null will be marshalled to "" for the xmi xml as defined in class org.eclipse.emf.ecore.impl.EcoreFactoryImpl:
public String convertEJavaClassToString(EDataType metaObject, Object instanceValue)
{
return instanceValue == null ? "" : ((Class<?>)instanceValue).getName();
}
The conterpart method:
public Class<?> createEJavaClassFromString(EDataType metaObject, String initialValue)
{
try
{
if (initialValue == null) return null;
else if ("boolean".equals(initialValue)) return boolean.class;
else if ("byte".equals(initialValue)) return byte.class;
else if ("char".equals(initialValue)) return char.class;
else if ("double".equals(initialValue)) return double.class;
else if ("float".equals(initialValue)) return float.class;
else if ("int".equals(initialValue)) return int.class;
else if ("long".equals(initialValue)) return long.class;
else if ("short".equals(initialValue)) return short.class;
else return Class.forName(initialValue);
}
catch (ClassNotFoundException e)
{
throw new WrappedException(e);
}
}
throws an Exception when trying to load a Class for name "". I think null instead of "" would be correct in convertEJavaClassToString.
It seems this is an inconistent implementation, we get an error in a ChangeDescription where a feature of type Class was set, the ChangeDescription stores "" which causes an error when we resume the ChangeRecorder.
Before someone asks: Yes, we store ChangeDescriptions. It works perfectlly, but now we have features of type Class the first time ...
If this is a bug, where is it possible to notify this?
Reagrds,
Tom
[Updated on: Wed, 05 October 2022 08:11] by Moderator
|
|
|
|
|
|
Re: Problem with Features of Type Class [message #1855311 is a reply to message #1855278] |
Fri, 07 October 2022 04:39  |
Eclipse User |
|
|
|
Hi
Yes, there is certainly a danger when changing one strange legacy behavior to a different behavior.
Legacy-wise, I'm wary of changing a ...toString method that doesn't return null to one that does.
Given the need for special nil XML handling, perhaps the null could/should have been handled before it was passed to convertToString.
Regards
Ed
|
|
|
Powered by
FUDForum. Page generated in 0.11336 seconds