Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CopyablePlugin does not copy empty lists --> invalid XML #576

Open
winfriedgerlach opened this issue Nov 21, 2024 · 5 comments
Open

CopyablePlugin does not copy empty lists --> invalid XML #576

winfriedgerlach opened this issue Nov 21, 2024 · 5 comments
Labels

Comments

@winfriedgerlach
Copy link

winfriedgerlach commented Nov 21, 2024

Cf. related issue eclipse-ee4j/jaxb-ri#1823

Unfortunately, the CopyablePlugin does not copy empty lists. This behavior may lead to invalid XML, if the XML Schema specifies a mandatory attribute (use="required") of list type with no restriction on the list's size - i.e., an XML document with the attribute being present but empty validates successfully, while an XML dockument lacking the attribute fails validation against the schema.

As the CopyablePlugin does not copy empty lists from attributes, a valid XML document (with an empty attribute of list type) becomes invalid when unmarshalled, copied, and marshalled again.

AFAIU, the problem originates from the implementation of jaxb-ri's AbstractListField.Accessor.hasSetValue(). This is used twice in jaxb-tools:

I do understand that lists of XML elements do not have the same problem (empty lists and "null" lists of XML elements are indistinguishable). So this problem really only applies to lists in XML attributes.

I would be interested to hear your opinion. Do you follow my argument that this is a bug? How could this be solved? Should lists from XML elements be treated differently than lists from XML attributes? If so, what could be done to achieve this?

Thanks in advance!

@laurentschoelens
Copy link
Collaborator

Hi @winfriedgerlach

Thanks for your report. Could you join MRE (Minimal Reproducible Example) so we can dig in more the process behind this issue ?

My first guess would be that on List attributes, initialization is done in getters.

laurentschoelens added a commit to laurentschoelens/jaxb-tools that referenced this issue Nov 21, 2024
winfriedgerlach added a commit to winfriedgerlach/jaxb-tools that referenced this issue Nov 25, 2024
…blem when copyTo copies empty lists as null
@winfriedgerlach
Copy link
Author

winfriedgerlach commented Nov 25, 2024

Hi @laurentschoelens, thanks for reacting to my issue!
I wrote a test that should demonstrate my problem, see master...winfriedgerlach:jaxb-tools:feature/#576-add-MRE
I hope this demonstrates the problem clearly (although it is a bit more than "minimal" 😉).

winfriedgerlach added a commit to winfriedgerlach/jaxb-tools that referenced this issue Nov 25, 2024
@laurentschoelens
Copy link
Collaborator

My guess is it's more related to jaxb marshalling on null attributes list rather than copyable plugin issue.

Depending on setting the following line in comment or not :

FooElement element = new FooElement();
// element.getBarAttribute().clear();

You'll get a failing (commented) or passing (uncommented) test result on marshalling to XML since by default, barAttribute is null.

@winfriedgerlach
Copy link
Author

winfriedgerlach commented Nov 27, 2024

@laurentschoelens you don't even need .clear(), element.getBarAttribute() will generate the list and then everything is fine again. My point is that I would expect that the CopyablePlugin generates code that copies XML entities in such a way that they remain "unchanged" from an XML point of view. Let's assume we use a non-validating marshaller:

// GIVEN XML is <FooElement BarAttribute=""/>
// WHEN unmarshalling, copyTo() (or clone()), marshalling
// THEN the XML is <FooElement/>

@laurentschoelens
Copy link
Collaborator

I need to dig more into this to check what happens on elements point of view (vs. Attributes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants