Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 317357 - XMLAnyObjectMapping has dead code in trunk
Summary: XMLAnyObjectMapping has dead code in trunk
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-19 09:13 EDT by Doug Clarke CLA
Modified: 2022-06-09 10:35 EDT (History)
4 users (show)

See Also:


Attachments
Proposed fix (4.98 KB, patch)
2010-12-10 14:53 EST, David McCann CLA
no flags Details | Diff
Supporting tests (9.31 KB, patch)
2010-12-10 15:59 EST, David McCann CLA
no flags Details | Diff
Proposed fix (20.65 KB, patch)
2010-12-14 15:02 EST, David McCann CLA
no flags Details | Diff
Supporting tests (11.69 KB, patch)
2010-12-14 15:02 EST, David McCann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Doug Clarke CLA 2010-06-19 09:13:02 EDT
Starting at line 350 of XMLAnyObjectMapping:

                    if (referenceDescriptor != null) {
                        ObjectBuilder builder = referenceDescriptor.getObjectBuilder();
                        objectValue = builder.buildObject(query, nestedRecord, joinManager);
                        Object updated = ((XMLDescriptor) referenceDescriptor).wrapObjectInXMLRoot(objectValue, next.getNamespaceURI(), next.getLocalName(), next.getPrefix(), false);
                        if(getConverter() != null) {
                            updated = getConverter().convertDataValueToObjectValue(objectValue, session, record.getUnmarshaller());
                        }
                        return updated;
                    } else if ((referenceDescriptor != null) && (getKeepAsElementPolicy() != UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT)) {
                        return buildObjectAndWrapInXMLRoot(referenceDescriptor, getConverter(), query, record, nestedRecord, joinManager, session, next, null, null);
                    } else {                        

The else if condition will never be met since the initial if condition addressed referenceDescriptor != null
Comment 1 David McCann CLA 2010-12-10 14:53:34 EST
Created attachment 184988 [details]
Proposed fix
Comment 2 David McCann CLA 2010-12-10 15:59:29 EST
Created attachment 184997 [details]
Supporting tests
Comment 3 David McCann CLA 2010-12-14 15:02:06 EST
Created attachment 185163 [details]
Proposed fix
Comment 4 David McCann CLA 2010-12-14 15:02:25 EST
Created attachment 185164 [details]
Supporting tests
Comment 5 David McCann CLA 2010-12-14 15:24:23 EST
The fix involves more than just removing the unreachable code;  the logic in that block needs to be reworked.  

This DOM platform use case involves unmapped Elements whose mappings are set to use XMLRoot.  There are three cases we need to handle here:

1)  KEEP_ALL_AS_ELEMENT or (referenceDescriptor == null && KEEP_UNKNOWN_AS_ELEMENT):

  - in this case we want to return the element
  - the returned element will be wrapped in a XMLRoot if there is no reference descriptor
  - the returned element may/may not be wrapped in an XMLRoot if there is a reference descriptor, as the descriptor decides if the value should be wrapped or not (as is done in SAX)

2)  If criteria for 1) above is not met and there is a reference descriptor:

  - the reference descriptor is used to build the object to return
  - the returned object may/may not be wrapped in an XMLRoot, as the descriptor decides if the value should be wrapped or not (as is done in SAX)

3)  If criteria is not met for either 1) or 2) above:

  - if the first child of the unknown element is TEXT, and contains a non-empty String, the String value will be wrapped in an XMLRoot
  - if the schema type is known and maps to an XML type (i.e. boolean, dateTime, etc.), the String value will be converted to the XML type before being wrapped in an XMLRoot
Comment 6 David McCann CLA 2010-12-14 15:34:57 EST
The logic change will apply to the collection use case as well.
Comment 7 David McCann CLA 2010-12-15 09:47:40 EST
Reviewed by:  matt.macivor@oracle.com
Tests: all unit tests pass as expected; oxm.mappings.anyobject.withoutgroupingelement.AnyObjectKeepAllAsElementTestCases

Revision: 8710
Comment 8 Eclipse Webmaster CLA 2022-06-09 10:35:36 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink