castor

SourceGen: ClassDescriptor.getExtends() returns always null

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.9.3.21, 1.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.1 M1
  • Fix Version/s: 1.1 M2
  • Component/s: XML code generator
  • Labels:
    None
  • Environment:
    Operating System: Windows 2000
    Platform: PC
  • Bugzilla Id:
    1043
  • Number of attachments :
    1

Description

The methode getExtends() of generated FieldDescriptor class always returns null:

class AFieldDescriptor extends BFieldDescriptor
{

public void getExtends()

{ return super.getExtends() }

}

Resolution:

class AClassDescriptor extends BClassDescriptor
{
public ClassDescriptorgetExtends()

{ return super.getExtends() }

}

Solution of this problem:

class AClassDescriptor extends BClassDescriptor
{
public ClassDescriptor getExtends()

{ return super; }

}

Activity

Hide
Keith Visco added a comment -

The solution is not as simple as that, because all the generated descriptors
eventually extend XMLClassDescriptorImpl, so simply return super; will cause
getExtends() to incorrectly return a non-null value. So we'll have to provide
some additional checks. ClassDescriptor#getExtends() doesn't necessary mean that
the Class itself extends (in the Java sense) any particular Class, #getExtends()
can return any ClassDescriptor that the said ClassDescriptor should inherit
from, even if the implementation doens't extend it programmatically.

For example:

AClassDescriptor implements XMLClassDescriptor {

private ClassDescriptor _inheritFrom = new BClassDescriptor();

public ClassDescriptor getExtends() { return _inheritFrom; }
}

Should be treated the same as:

AClassDescriptor extends BClassDescriptor {

public ClassDescriptor getExtends() { return super; }

}

But the following would be incorrect...

BClassDescriptor extends XMLClassDescriptorImpl {

public ClassDescriptor getExtends() { return super; } }

}

I'm assigning this to Arnaud so that he can look into it further...

Show
Keith Visco added a comment - The solution is not as simple as that, because all the generated descriptors eventually extend XMLClassDescriptorImpl, so simply return super; will cause getExtends() to incorrectly return a non-null value. So we'll have to provide some additional checks. ClassDescriptor#getExtends() doesn't necessary mean that the Class itself extends (in the Java sense) any particular Class, #getExtends() can return any ClassDescriptor that the said ClassDescriptor should inherit from, even if the implementation doens't extend it programmatically. For example: AClassDescriptor implements XMLClassDescriptor { private ClassDescriptor _inheritFrom = new BClassDescriptor(); public ClassDescriptor getExtends() { return _inheritFrom; } } Should be treated the same as: AClassDescriptor extends BClassDescriptor { public ClassDescriptor getExtends() { return super; } } But the following would be incorrect... BClassDescriptor extends XMLClassDescriptorImpl { public ClassDescriptor getExtends() { return super; } } } I'm assigning this to Arnaud so that he can look into it further...
Hide
Edward Kuns added a comment -

I ran into this just a couple days ago. The problem is that generated code incorrectly overrides the getExtends() method of XMLClassDescriptorImpl in such a way that it effectively returns not what it extends but what is extended by the schema element it extends. That is, its grandparent.

The fix is simple. Remove the generated code for getExtends() so the method in XMLClassDescriptorImpl will be used, which returns the correct value already.

If the schema defines type "A" that is restricted by type "B" that is restricted by type "C", then the *generated* getExtends for "C" will return the class descriptor for "A". Removing the generated getExtends(), then calling getExtends() for "C" will return the class descriptor for "B" and calling getExtends() for "B" will return the class descriptor for "A".

Show
Edward Kuns added a comment - I ran into this just a couple days ago. The problem is that generated code incorrectly overrides the getExtends() method of XMLClassDescriptorImpl in such a way that it effectively returns not what it extends but what is extended by the schema element it extends. That is, its grandparent. The fix is simple. Remove the generated code for getExtends() so the method in XMLClassDescriptorImpl will be used, which returns the correct value already. If the schema defines type "A" that is restricted by type "B" that is restricted by type "C", then the *generated* getExtends for "C" will return the class descriptor for "A". Removing the generated getExtends(), then calling getExtends() for "C" will return the class descriptor for "B" and calling getExtends() for "B" will return the class descriptor for "A".
Hide
Edward Kuns added a comment -

Note – in the common case where type "A" is restricted by type "B" ... calling the generated getExtends() for type "B" returns null, always, since "A" does not restrict or extend another schema type definition. This is the bug as described above.

Show
Edward Kuns added a comment - Note – in the common case where type "A" is restricted by type "B" ... calling the generated getExtends() for type "B" returns null, always, since "A" does not restrict or extend another schema type definition. This is the bug as described above.
Hide
Edward Kuns added a comment -

Having thought about this some more, the fix is indeed to remove the generated getExtends() method. Because:

The code currently generates a getExtends() that returns null for any base class. Any extending class generates a getExtends() that calls super.getExtends(), which of course calls the getExtends() in the base class that returns null. Thus, this will always return null for all generated classes.

If we simply remove the generated getExtends() method, then the implementation in XMLClassDescriptorImpl will always do the right thing. This is because our generated source calls setExtendsWithoutFlatten() only if it extends another descriptor.

Show
Edward Kuns added a comment - Having thought about this some more, the fix is indeed to remove the generated getExtends() method. Because: The code currently generates a getExtends() that returns null for any base class. Any extending class generates a getExtends() that calls super.getExtends(), which of course calls the getExtends() in the base class that returns null. Thus, this will always return null for all generated classes. If we simply remove the generated getExtends() method, then the implementation in XMLClassDescriptorImpl will always do the right thing. This is because our generated source calls setExtendsWithoutFlatten() only if it extends another descriptor.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: