-
Notifications
You must be signed in to change notification settings - Fork 64
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
Fixes a serious problem in xmlbeans #10
base: trunk
Are you sure you want to change the base?
Conversation
…s in case there are an attribute and element with same name in the schema: SchemaTypeCodePrinter.java#printStaticFields writes an array named PROPERTY_QNAME. It depends on the supplied argument Map<QName, Integer> qnameMap. But QName is not unique. If there is an attribute and element with same name, the second replaces the first when the Map is filled although the index is incremented for each of them. So, indices of all subsequent members are pointing to the wrong entry. Now SchemaProperty is used as key for above map instead of QName. SchemaProperty instances are unique.
I raised https://issues.apache.org/jira/browse/XMLBEANS-644 Could you provide a schema file that can be used for testing this? |
I ran the unit tests with this change and they pass - but that is not not enough without a new test case to validate the changes. |
Hi, unfortunately all xsds i used are from my company. I cannot share it.
But i will try to create an example xsd and send it to you.
Am 28. November 2023 12:41:39 MEZ schrieb PJ Fanning ***@***.***>:
I ran the unit tests with this change and they pass - but that is not not enough without a new test case to validate the changes.
--
Reply to this email directly or view it on GitHub:
#10 (comment)
You are receiving this because you modified the open/close state.
Message ID: ***@***.***>
--
Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.
|
I created my own xsd. It would be nice to get a better one.
The scomp tool fails to generate code for this schema. The code doesn't even get to the SchemaTypeCodePrinter stage. XMLBeans has code in StscState that validates the schema. There could be a different issue with my xsd but StscState rejects it in the So far, it looks like bigger changes are needed than just changing SchemaTypeCodePrinter. There are also validations in SchemaTypeSystemImpl that appear to fail too - again because duplicate QNames will make assertContainersHelper fail. |
If you compile the following XSD and look into the impl source, you see
that the getter/setter for attribute Attr use the wrong index from
PROPERTY_QNAME array. This problem is fixed by my changes. Maybe there
are more problems with duplicate QNames.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xs:element name="Object">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" minOccurs="0"/>
<xs:element name="Code" type="xs:string" minOccurs="0"/>
<xs:element name="Value" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="Code" type="xs:string"/>
<xs:attribute name="Attr" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
Am 28.11.2023 um 13:38 schrieb PJ Fanning:
…
I created my own xsd. It would be nice to get a better one.
|<xs:schema attributeFormDefault="qualified"
elementFormDefault="qualified"
targetNamespace="https://xmlbeans.apache.org/XMLBEANS-644"
xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element
name="xmlbeans644"> <xs:complexType> <xs:sequence> <xs:element
type="xs:string" name="data"/> <xs:element name="file">
<xs:complexType> <xs:simpleContent> <xs:extension base="xs:string">
<xs:attribute type="xs:string" name="data"/> </xs:extension>
</xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence>
</xs:complexType> </xs:element> </xs:schema> |
The scomp tool fails to generate code for this schema. The code
doesn't even get to the SchemaTypeCodePrinter stage. XMLBeans has code
in StscState that validates the schema. There could be a different
issue with my xsd but StscState rejects it in the |void
addDocumentType(SchemaTypeImpl type, QName name)| call because of the
duplicate QName.
So far, it looks like bigger changes are needed than just changing
SchemaTypeCodePrinter.
—
Reply to this email directly, view it on GitHub
<#10 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMTV2H2KWXPCIZMGOI7Z7NDYGXLMDAVCNFSM6AAAAAA75OLFEOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRZG43DANZXGY>.
You are receiving this because you modified the open/close
state.Message ID: ***@***.***>
|
If you compile the following XSD and look into the impl source, you see
that the getter/setter for attribute Attr use the wrong index from
PROPERTY_QNAME array. This problem is fixed by my changes.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xs:element name="Object">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" minOccurs="0"/>
<xs:element name="Code" type="xs:string" minOccurs="0"/>
<xs:element name="Value" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="Code" type="xs:string"/>
<xs:attribute name="Attr" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
Am 28.11.2023 um 13:38 schrieb PJ Fanning:
…
I created my own xsd. It would be nice to get a better one.
|<xs:schema attributeFormDefault="qualified"
elementFormDefault="qualified"
targetNamespace="https://xmlbeans.apache.org/XMLBEANS-644"
xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element
name="xmlbeans644"> <xs:complexType> <xs:sequence> <xs:element
type="xs:string" name="data"/> <xs:element name="file">
<xs:complexType> <xs:simpleContent> <xs:extension base="xs:string">
<xs:attribute type="xs:string" name="data"/> </xs:extension>
</xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence>
</xs:complexType> </xs:element> </xs:schema> |
The scomp tool fails to generate code for this schema. The code
doesn't even get to the SchemaTypeCodePrinter stage. XMLBeans has code
in StscState that validates the schema. There could be a different
issue with my xsd but StscState rejects it in the |void
addDocumentType(SchemaTypeImpl type, QName name)| call because of the
duplicate QName.
So far, it looks like bigger changes are needed than just changing
SchemaTypeCodePrinter.
—
Reply to this email directly, view it on GitHub
<#10 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMTV2H2KWXPCIZMGOI7Z7NDYGXLMDAVCNFSM6AAAAAA75OLFEOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRZG43DANZXGY>.
You are receiving this because you modified the open/close
state.Message ID: ***@***.***>
|
the new xsd has the same issues with validations failing in StscState and SchemaTypeSystemImpl - the scomp job does not get as far as SchemaTypeCodePrinter |
Ok, not in my version of xmlbeans. My version is based on an older
commit. Let me check tomorrow (my time is GMT+1), if that is the point.
Does it succeed if you rename the Code attribute?
Am 28.11.2023 um 20:31 schrieb PJ Fanning:
…
the new xsd has the same issues with validations failing in StscState
and SchemaTypeSystemImpl - the scomp job does not get as far as
SchemaTypeCodePrinter
—
Reply to this email directly, view it on GitHub
<#10 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AMTV2H2UYUEM5E5YFERJJHTYGY32VAVCNFSM6AAAAAA75OLFEOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZQGU2DAOBXGE>.
You are receiving this because you modified the open/close
state.Message ID: ***@***.***>
|
I have rebased my changes to the latest commit, build all (my production is done with ant target package) and running scomp: No errors, jar has been built.
(BTW: to succeed with ant I was forced to do some changes in build.xml)
Schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema targetNamespace=http://example.org/Schema1 elementFormDefault="qualified" attributeFormDefault="qualified">
<xs:element name="Object">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" minOccurs="0"/>
<xs:element name="Code" type="xs:string" minOccurs="0"/>
<xs:element name="Value" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="Code" type="xs:string"/>
<xs:attribute name="Attr" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
XSDCONFIG
<xb:config xmlns:xb=http://xml.apache.org/xmlbeans/2004/02/xbean/config>
<xb:namespace uri="##any">
<xb:package>example.schema1</xb:package>
</xb:namespace>
<xb:namespace uriprefix="Schema1">
<xb:prefix>Schema1</xb:prefix>
</xb:namespace>
</xb:config>
COMMAND:
C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\bin\scomp.cmd -ms 1024m -compiler C:\Entwicklung\Java\AdoptOpenJDK\jdk-17.0.9+9\bin\javac.exe -src src -out Schema1.jar -verbose Schema1.xsd Schema1.xsdconfig
OUTPUT:
Apache Software Foundation, org.apache.xmlbeans.XmlBeans version 5.2.1-ZNT
Loading schema file Schema1.xsd
Loading config file Schema1.xsdconfig
Time to build schema type system: 0.476 seconds
created binary: org/apache/xmlbeans/metadata/system/sDF907B31B716D7AB6C1C541FC0DBB7C6/objecta8b7doctype.xsb
created binary: org/apache/xmlbeans/metadata/system/sDF907B31B716D7AB6C1C541FC0DBB7C6/object4d32elemtype.xsb
created binary: org/apache/xmlbeans/metadata/system/sDF907B31B716D7AB6C1C541FC0DBB7C6/objectelement.xsb
created binary: org/apache/xmlbeans/metadata/system/sDF907B31B716D7AB6C1C541FC0DBB7C6/index.xsb
created binary: org/apache/xmlbeans/metadata/element/http_3A_2F_2Fexample_2Eorg_2FSchema1/Object.xsb
created binary: org/apache/xmlbeans/metadata/namespace/http_3A_2F_2Fexample_2Eorg_2FSchema1/xmlns.xsb
created binary: org/apache/xmlbeans/metadata/javaname/example/schema1/ObjectDocument.xsb
created binary: org/apache/xmlbeans/metadata/javaname/example/schema1/ObjectDocument/Object.xsb
created source: C:\Entwicklung\Fehler\XMLBeans\Schema1\src\org\apache\xmlbeans\metadata\system\sDF907B31B716D7AB6C1C541FC0DBB7C6\TypeSystemHolder.java
created source: C:\Entwicklung\Fehler\XMLBeans\Schema1\src\example\schema1\ObjectDocument.java
created source: C:\Entwicklung\Fehler\XMLBeans\Schema1\src\example\schema1\impl\ObjectDocumentImpl.java
Time to generate code: 0.046 seconds
compile command: C:\Entwicklung\Java\AdoptOpenJDK\jdk-17.0.9+9\bin\javac.exe -J-Xms1024m @C:\Users\rbeninga\AppData\Local\Temp\javac8420294166929622878.tmp
warning: [options] bootstrap class path not set in conjunction with -source 8
[parsing started SimpleFileObject[C:\Entwicklung\Fehler\XMLBeans\Schema1\src\org\apache\xmlbeans\metadata\system\sDF907B31B716D7AB6C1C541FC0DBB7C6\TypeSystemHolder.java]]
[parsing completed 9ms]
[parsing started SimpleFileObject[C:\Entwicklung\Fehler\XMLBeans\Schema1\src\example\schema1\ObjectDocument.java]]
[parsing completed 5ms]
[parsing started SimpleFileObject[C:\Entwicklung\Fehler\XMLBeans\Schema1\src\example\schema1\impl\ObjectDocumentImpl.java]]
[parsing completed 12ms]
[search path for source files: C:\Users\rbeninga\AppData\Local\Temp\xbean2968360996771154739.d\classes,C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar,C:\Entwicklung\Fehler\XMLBeans\Schema1,C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\bin\..\lib\log4j-api-2.21.1.jar,C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\bin\..\lib\log4j-core-2.21.1.jar,C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\bin\..\lib\xmlbeans-5.2.1-ZNT-javadoc.jar,C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\bin\..\lib\xmlbeans-5.2.1-ZNT-sources.jar,C:\lib\tools.jar]
[search path for class files: C:\Entwicklung\Java\AdoptOpenJDK\jdk-17.0.9+9\lib\modules,C:\Users\rbeninga\AppData\Local\Temp\xbean2968360996771154739.d\classes,C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar,C:\Entwicklung\Fehler\XMLBeans\Schema1,C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\bin\..\lib\log4j-api-2.21.1.jar,C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\bin\..\lib\log4j-core-2.21.1.jar,C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\bin\..\lib\xmlbeans-5.2.1-ZNT-javadoc.jar,C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\bin\..\lib\xmlbeans-5.2.1-ZNT-sources.jar,C:\lib\tools.jar]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/SchemaTypeSystem.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/SchemaTypeLoader.class)]
[loading /modules/java.base/java/lang/Object.class]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/impl/schema/SchemaTypeLoaderBase.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/impl/schema/ElementFactory.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/impl/schema/AbstractDocumentFactory.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/impl/schema/DocumentFactory.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/impl/schema/SimpleTypeFactory.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/XmlObject.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/XmlTokenSource.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/SchemaType.class)]
[loading /modules/java.base/java/lang/String.class]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/XmlString.class)]
[loading /modules/java.xml/javax/xml/namespace/QName.class]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/QNameSet.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/impl/values/XmlComplexContentImpl.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/impl/values/XmlObjectBase.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/impl/values/TypeStoreUser.class)]
[loading /modules/java.base/java/io/Serializable.class]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/SimpleValue.class)]
[loading /modules/java.base/java/lang/Deprecated.class]
[loading /modules/java.base/java/lang/Override.class]
[loading /modules/java.base/java/lang/annotation/Annotation.class]
[loading /modules/java.base/java/lang/annotation/Retention.class]
[loading /modules/java.base/java/lang/annotation/RetentionPolicy.class]
[loading /modules/java.base/java/lang/annotation/Target.class]
[loading /modules/java.base/java/lang/annotation/ElementType.class]
Round 1:
input files: {org.apache.xmlbeans.metadata.system.sDF907B31B716D7AB6C1C541FC0DBB7C6.TypeSystemHolder, example.schema1.ObjectDocument, example.schema1.impl.ObjectDocumentImpl}
annotations: [java.lang.Override]
last round: false
Round 2:
input files: {}
annotations: []
last round: true
[checking org.apache.xmlbeans.metadata.system.sDF907B31B716D7AB6C1C541FC0DBB7C6.TypeSystemHolder]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/XmlException.class)]
[loading /modules/java.base/java/lang/Error.class]
[loading /modules/java.base/java/lang/Exception.class]
[loading /modules/java.base/java/lang/Throwable.class]
[loading /modules/java.base/java/lang/RuntimeException.class]
[loading /modules/java.base/java/io/IOException.class]
[loading /modules/java.base/java/lang/AutoCloseable.class]
[loading /modules/java.base/java/lang/Class.class]
[wrote C:\Users\rbeninga\AppData\Local\Temp\xbean2968360996771154739.d\classes\org\apache\xmlbeans\metadata\system\sDF907B31B716D7AB6C1C541FC0DBB7C6\TypeSystemHolder.class]
[checking example.schema1.ObjectDocument]
[wrote C:\Users\rbeninga\AppData\Local\Temp\xbean2968360996771154739.d\classes\example\schema1\ObjectDocument$Object.class]
[wrote C:\Users\rbeninga\AppData\Local\Temp\xbean2968360996771154739.d\classes\example\schema1\ObjectDocument.class]
[checking example.schema1.impl.ObjectDocumentImpl]
[loading /modules/java.base/java/util/List.class]
[loading /modules/java.xml/org/xml/sax/SAXException.class]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/impl/values/TypeStore.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/impl/values/NamespaceManager.class)]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/impl/common/PrefixResolver.class)]
[loading /modules/java.base/java/lang/Byte.class]
[loading /modules/java.base/java/lang/Character.class]
[loading /modules/java.base/java/lang/Short.class]
[loading /modules/java.base/java/lang/Long.class]
[loading /modules/java.base/java/lang/Float.class]
[loading /modules/java.base/java/lang/Integer.class]
[loading /modules/java.base/java/lang/Double.class]
[loading /modules/java.base/java/lang/Boolean.class]
[loading /modules/java.base/java/lang/Void.class]
[loading C:\Entwicklung\Programme\XMLBeans\xmlbeans-5.2.1-ZNT\lib\xmlbeans-5.2.1-ZNT.jar(/org/apache/xmlbeans/XmlAnySimpleType.class)]
[loading /modules/java.base/java/util/function/IntFunction.class]
[loading /modules/java.base/java/util/function/Function.class]
[wrote C:\Users\rbeninga\AppData\Local\Temp\xbean2968360996771154739.d\classes\example\schema1\impl\ObjectDocumentImpl$ObjectImpl.class]
[wrote C:\Users\rbeninga\AppData\Local\Temp\xbean2968360996771154739.d\classes\example\schema1\impl\ObjectDocumentImpl.class]
[total 462ms]
1 warning
Time to compile code: 0.874 seconds
Compiled types to: Schema1.jar
…--
Servus
Reiner
From: PJ Fanning ***@***.***>
Sent: Tuesday, November 28, 2023 8:32 PM
To: apache/xmlbeans ***@***.***>
Cc: reinerben ***@***.***>; State change ***@***.***>
Subject: Re: [apache/xmlbeans] Fixes a serious problem in xmlbeans (PR #10)
the new xsd has the same issues with validations failing in StscState and SchemaTypeSystemImpl - the scomp job does not get as far as SchemaTypeCodePrinter
—
Reply to this email directly, view it on GitHub<#10 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AMTV2H2UYUEM5E5YFERJJHTYGY32VAVCNFSM6AAAAAA75OLFEOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZQGU2DAOBXGE>.
You are receiving this because you modified the open/close state.Message ID: ***@***.***>
|
added with e46a709 |
Fixes a serious problem which completely messed up getters and setters in case there are an attribute and element with same name in the schema:
SchemaTypeCodePrinter.java#printStaticFields writes an array named PROPERTY_QNAME. It depends on the supplied argument Map<QName, Integer> qnameMap. But QName is not unique. If there is an attribute and element with same name, the second replaces the first when the Map is filled although the index is incremented for each of them. So, indices of all subsequent members are pointing to the wrong entry.
Now SchemaProperty is used as key for above map instead of QName. SchemaProperty instances are unique.