"Todd V. Jonker" wrote:
>
> I'm attempting to deal with the various getter/setter discovery problems
> that have been floating around. Among the many, uh, "questionable" passages
> I've found, this one strikes me as particularly troublesome:
>
> Class org.exolab.castor.mapping.loader.Types has this method:
>
> /**
> * Maps from a primitive Java type to a Java class. Returns the same
> class
> * if <tt>type</tt> is not a primitive. The following conversion
> applies:
> * <pre>
> * From To
> * -------------- ---------------
> * Boolean.TYPE Boolean.class
> * Byte.TYPE Byte.class
> * Character.TYPE Character.class
> * Short.TYPE Short.class
> * Integer.TYPE Integer.class
> * Long.TYPE Long.class
> * Float.TYPE Float.class
> * Double.TYPE Double.class
> * </pre>
> *
> * @param type The Java type (primitive or not)
> * @return A comparable non-primitive Java type
> */
> public static Class typeFromPrimitive( Class type )
> {
> /// Fix for arrays
> if ((type != null) && (type.isArray())
> && !type.getComponentType().isPrimitive()) {
> return typeFromPrimitive( type.getComponentType() );
> }
> /// end fix
>
> for ( int i = 0 ; i < _typeInfos.length ; ++i ) {
> if ( _typeInfos[ i ].primitive == type )
> return _typeInfos[ i ].javaType;
> }
> return type;
> }
>
> It's that "Fix for arrays" bit that�s worrisome. It extracts the basic
> component type from an array type, but that's not what the function is
> documented to do.
Fair enough...the documentation needs to be amended. That fix for arrays
was added
because without it, there were even more issues. I believe the calls to
that code in MappingLoader are correct...If you see places in
MappingLoader
that you feel are incorrectly calling the method...or getting hit by the
"Fix for arrays" please let me know.
> In fact, that change breaks several call-sites that do NOT expect that
> behavior. In particular, the findAccessor methods in FieldMolder and
> MappingLoader. When trying to find a call-compatable method, such type
> transformations are not appropriate and will lead to bad matches.
>
> I've also noticed that the (static) findAccessor methods in FieldMolder and
> MappingLoader are an obvious case of copy-and-rape coding gone wrong.
MappingLoader came first, initially written by Assaf for Castor JDO...
it was shared by both Castor-JDO and Castor-XML. Apparently
Castor XML and Castor JDO were striving for different things.
I wanted to add more abilities to the mapping API for Castor XML...
such as inheritence, arrays, abstract classes, interfaces, etc.
Castor JDO was against this, at least at the time...
In an attempt to break Castor JDO away from Castor XML, Thomas Yip wrote
the FieldMolder.
I try to patch MappingLoader everynow and then...but I need to be
careful
because it's still shared between both frameworks...
> The latter has obviously been (correctly) extended and modified, but the former
> has not. I hypothesize that this is leading to some of the problems that we
> have seen reported on the list lately.
>
Probably...
> I'm attempting to refactor the noted repeated/broken code into a single
> place in the Types class. I'll submit the patches to the list once things
> seem to be working. If I can learn how to write and run test cases I'll
> submit those as well.
Some advice. Submit changes in small sections. Don't wait until you have
a ton
of changes...it will be difficult to review. And test cases are a must
for changes to low level classes like those. That code has been around
for years, and while I admit there needs to be some reworking as I've
been wanting to really clean up MappingLoader for a while now, it needs
to be done with care.
>
> Along the way I've written some code that applies a basic best-fit algorithm
> when looking for accessors, instead of the current first-match approach. I
> think this will resolve some of the accessor-not-found problems that arose
> in 0.9.3.9
>
> I would love to be contacted off-list by anybody knowledgeable in this code
> area.
Thomas Yip, Oleg Nitz, and myself are probably the best ones to talk to
about that area of the code. I don't mess around with the JDO side of
things, so Thomas can probably help you more with FieldMolder. I'll help
you where I can...
Thanks,
--Keith
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev