eclipse-ee4j / jaxb-fi

Apache License 2.0
8 stars 10 forks source link

Decoder shifts prefix and namespace names by one #31

Open Tomas-Kraus opened 14 years ago

Tomas-Kraus commented 14 years ago

The source of the problem is the built-in xml namespace http://www.w3.org/XML/1998/namespace. Those entries are not included in the PREFIX and NAMESPACE NAME tables but decoder knows that hey are there and that they got assigned index number '1'. This is described in the spec, point 7.2.21 and 7.2.22.

Example xml:

.... the content... Example prefix table: 1: xml (This entry is built-in and is not included in the fastinfoset vocabulary table) 2: prefix1 3: prefix2 The easiest way to explain that is by using SAX decoder so during decoding the DefaultHandler.startPrefixMapping method: DefaultHandler.startPrefixMapping (String prefix, String uri) receives the following notifications: 1\. prefix="xml", uri="http://www.w3.org/XML/1998/namespace" 2\. prefix="prefix1", uri="namespace1" instead of receiving: 1\. prefix="prefix1", uri="namespace1" 2\. prefix="prefix2", uri="namespace2" So during decoding all the prefixes and namespace names are shifted by one. This bug can be fixed by replacing Decoder.decodeTableItems(QualifiedNameArray array, boolean isAttribute) method below: ============================================================================ private void decodeTableItems(QualifiedNameArray array, boolean isAttribute) throws FastInfosetException, IOException { for (int i = 0; i < decodeNumberOfItemsOfSequence(); i++) { final int b = read(); String prefix = ""; int prefixIndex = -1; if ((b & EncodingConstants.NAME_SURROGATE_PREFIX_FLAG) > 0) { prefixIndex = decodeIntegerIndexOnSecondBit(); prefix = _v.prefix._array[prefixIndex - 1]; } String namespaceName = ""; int namespaceNameIndex = -1; if ((b & EncodingConstants.NAME_SURROGATE_NAME_FLAG) > 0) { namespaceNameIndex = decodeIntegerIndexOnSecondBit(); namespaceName = _v.namespaceName._array[namespaceNameIndex - 1]; } if (namespaceName == "" && prefix != "") { throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.missingNamespace")); } final int localNameIndex = decodeIntegerIndexOnSecondBit(); final String localName = _v.localName.get(localNameIndex); QualifiedName qualifiedName = new QualifiedName(prefix, namespaceName, localName, prefixIndex, namespaceNameIndex, localNameIndex, _charBuffer); if (isAttribute) { qualifiedName.createAttributeValues(_duplicateAttributeVerifier.MAP_SIZE); } array.add(qualifiedName); } } ============================================================================ By the method below (fixed lines are annotated): ============================================================================ private void decodeTableItems(QualifiedNameArray array, boolean isAttribute) throws FastInfosetException, IOException { for (int i = 0; i < decodeNumberOfItemsOfSequence(); i++) { final int b = read(); String prefix = ""; int prefixIndex = -1; if ((b & EncodingConstants.NAME_SURROGATE_PREFIX_FLAG) > 0) { prefixIndex = decodeIntegerIndexOnSecondBit(); // fix for 7.2.21 prefix = _v.prefix._array[prefixIndex - 1]; } String namespaceName = ""; int namespaceNameIndex = -1; if ((b & EncodingConstants.NAME_SURROGATE_NAME_FLAG) > 0) { namespaceNameIndex = decodeIntegerIndexOnSecondBit(); // fix for 7.2.22 namespaceName = _v.namespaceName._array[namespaceNameIndex - 1]; } if (namespaceName == "" && prefix != "") { throw newFastInfosetException(CommonResourceBundle.getInstance().getString("message.missingNamespace")); } final int localNameIndex = decodeIntegerIndexOnSecondBit(); final String localName = _v.localName.get(localNameIndex); QualifiedName qualifiedName = new QualifiedName(prefix, namespaceName, localName, prefixIndex, namespaceNameIndex, localNameIndex, _charBuffer); if (isAttribute) { qualifiedName.createAttributeValues(_duplicateAttributeVerifier.MAP_SIZE); } array.add(qualifiedName); } } #### Environment Operating System: All Platform: All #### Affected Versions [current]
Tomas-Kraus commented 5 years ago
Tomas-Kraus commented 14 years ago

@glassfishrobot Commented Reported by agladkowski

Tomas-Kraus commented 14 years ago

@glassfishrobot Commented Was assigned to oleksiys

Tomas-Kraus commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA FI-31