eclipse-ee4j / jaxb-ri

Jaxb RI
https://eclipse-ee4j.github.io/jaxb-ri/
BSD 3-Clause "New" or "Revised" License
202 stars 110 forks source link

"Item" is already defined error with catalogs, bindings and mixed absolute and relative URLs #1045

Open Tomas-Kraus opened 9 years ago

Tomas-Kraus commented 9 years ago

This is somewhat complex setup, please take a look at the prepared example (attached) first.

I am trying to do a clean compilation of the GML 3.1.1 schema using catalogs and binding files.

I've created local copies of files in the w3c and ogc folders and rewrite URLs using the following catalog file:

REWRITE_SYSTEM "http://www.w3.org" "w3c" REWRITE_SYSTEM "http://schemas.opengis.net" "ogc"

In the GML schema there is one schema which imports SMIL via the absolute URL:

**defaultStyle.xsd**<import namespace="http://www.w3.org/2001/SMIL20/" schemaLocation="http://schemas.opengis.net/gml/3.1.1/smil/smil20.xsd"/>

My understanding is that http://schemas.opengis.net/gml/3.1.1/smil/smil20.xsd will be resolved to ogc/gml/3.1.1/smil/smil20.xsd via catalog.

The smil20.xsd imports smil20-language.xsd via relative URL:

**smil20.xsd**<import namespace="http://www.w3.org/2001/SMIL20/Language" schemaLocation="smil20-language.xsd"/>

The smil20-language.xsd imports the smil20.xsd also via relative URL:

**smil20-language.xsd**<import namespace="http://www.w3.org/2001/SMIL20/" schemaLocation="smil20.xsd"/>

When I try to compile this I get the following stream of errors:

[ERROR] 'structureModuleAttrs' is already defined
  line 45 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 37 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'skipContentAttrs' is already defined
  line 51 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 45 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'alternateContentAttrs' is already defined
  line 58 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 51 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'nonNegativeDecimalType' is already defined
  line 66 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 58 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'animate' is already defined
  line 66 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 66 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'animatePrototype' is already defined
  line 72 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 67 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'animNamedTargetAttrs' is already defined
  line 84 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 72 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'animAddAccumAttrs' is already defined
  line 102 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 84 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'animValuesAttrs' is already defined
  line 108 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 102 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'animSetValuesAttrs' is already defined
  line 111 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 108 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'animTargetAttrs' is already defined
  line 114 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 111 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'animModeAttrs' is already defined
  line 125 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 114 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'animateMotion' is already defined
  line 125 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 125 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'animateMotionPrototype' is already defined
  line 131 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 126 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'animateColor' is already defined
  line 131 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 131 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'animateColorPrototype' is already defined
  line 137 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 132 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'set' is already defined
  line 137 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 137 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'setPrototype' is already defined
  line 145 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 138 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'syncBehaviorAttrs' is already defined
  line 149 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 145 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'syncBehaviorType' is already defined
  line 157 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 149 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'syncBehaviorDefaultAttrs' is already defined
  line 161 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 157 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'syncBehaviorDefaultType' is already defined
  line 169 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 161 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'restartTimingAttrs' is already defined
  line 172 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 169 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'restartTimingType' is already defined
  line 180 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 172 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'restartDefaultAttrs' is already defined
  line 183 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 180 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'restartDefaultType' is already defined
  line 191 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 183 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'fillTimingAttrs' is already defined
  line 194 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 191 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'fillTimingAttrsType' is already defined
  line 204 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 194 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'fillDefaultAttrs' is already defined
  line 207 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 204 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'fillDefaultType' is already defined
  line 217 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 207 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'beginEndTimingAttrs' is already defined
  line 221 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 217 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'durTimingAttrs' is already defined
  line 224 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 221 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'repeatTimingAttrs' is already defined
  line 228 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 224 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'deprecatedRepeatTiming' is already defined
  line 231 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 228 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] 'minMaxTimingAttrs' is already defined
  line 235 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

[ERROR] (related to above error) the first definition appears here
  line 231 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/JAXB-1045/ogc/gml/3.1.1/smil/smil20.xsd

Failed to parse a schema.

Note that XJC complains about the identical URLs, also references the same lines (however in a wrong order which is a bit weird).

If I change both of the relative URLs in the SMIL schemas to absolute URLs, it does work. Of course, I don't want this workaround as I don't want to patch external schemas.

I've also reproduced it on a "reduced" test case with simple schemas (see the cd.zip attachment).

The problem arises only if bindings files are used. When compiling without bindings, it works (see success.bat and failure.bat in cd.zip). failure.bat gives the following error trace:

[ERROR] 'd' is already defined
  line 9 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/1/ab/d.xsd

[ERROR] (related to above error) the first definition appears here
  line 9 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/1/ab/d.xsd

[ERROR] 'DType' is already defined
  line 16 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/1/ab/d.xsd

[ERROR] (related to above error) the first definition appears here
  line 10 of file:/C:/Projects/workspaces/jaxb2-basics/jaxb-ri-tests/1/ab/d.xsd

Failed to parse a schema.

Lines are quite interesting. The element 'd' is reported two times on the same line. The type 'DType' is reported two times - one on the opening <complexType ...> tag of the type and once on the closing tag:

01<?xml version="1.0" encoding="UTF-8"?>
02<schema 
03  xmlns="http://www.w3.org/2001/XMLSchema" 04 targetNamespace="urn:d" elementFormDefault="qualified"
05  xmlns:d="urn:d"
06  xmlns:e="urn:e">
07
08  <import namespace="urn:e" schemaLocation="e.xsd"/>
09  <element name="d" type="d:DType"/>
10  <complexType name="DType">
11      <sequence>
12          <element name="s" type="string"/>
13          <element name="e" type="e:EType"/>
14      </sequence>
15  </complexType>
16</schema>

My guess is that the graph:

somehow causes problems with schema 2. I think the problem might be different paths to schema 2. The URLs are finally rewritten via catalog to the same URL but the same document gets parsed two times.

This is quite a showstopper for me at the moment. I am forced to patch schemas on a very big scale, which is extremely ugly.

Tomas-Kraus commented 5 years ago
Tomas-Kraus commented 9 years ago

@glassfishrobot Commented Reported by lexi

Tomas-Kraus commented 9 years ago

@glassfishrobot Commented lexi said: Please consider a fix in the https://github.com/gf-metro/jaxb/pull/7

The problem here is that when the entity resolver resolves some systemId, you get an input source with the stream AND a resolved systemId. Subsequent resolutions (when you for instance have an import or an include) will use this resolved system id. This may result in some schemas addressed by an unresolved and by a resolved system id - despite being placed in the same local source.

The fix is simple: when resolving, only provide the stream and don't change the system id (or public id) of the input source. This still works well - parsers take XML from the stream. And this corrects the problem since system id does not change.


I understand that we're talking customer-facing interface here so you probably have to carefully consider if you apply the fixes or not. I am persuaded that what I propose is the correct behaviour, so I will want to fix it anyway (in maven-jaxb2-plugin, at least). I think I can make workarounds via the entity resolver for #1044 and #1045 as it is basically the entity resolver logic which is changed here. What I can't do is #1046 since it addresses the interna of the DOMForest which is not accessible. But I think this fix is not dangerous at all.

Please let me know what you think of the fixes and if we can work them into the XJC release.

Tomas-Kraus commented 9 years ago

@glassfishrobot Commented File: cd.zip Attached By: lexi

Tomas-Kraus commented 9 years ago

@glassfishrobot Commented File: gml-v_3_1_1.zip Attached By: lexi

Tomas-Kraus commented 9 years ago

@glassfishrobot Commented Was assigned to yaroska

Tomas-Kraus commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA JAXB-1045

Tomas-Kraus commented 6 years ago

@bgedik Commented Any progress on this?

highsource commented 5 years ago

Should I provide a pull request to fix this?

bravehorsie commented 5 years ago

@highsource You are most welcome to 👍

highsource commented 5 years ago

@bravehorsie Do I need to sign some CLA? I've signed some CLA with Sun or Oracle ages ago.

highsource commented 5 years ago

@bravehorsie I'd like to add a test for my three schemas + catalog file first. Where should I put them in the project? I see almost none XJC tests (which is surprizing).

highsource commented 5 years ago

So that I don't lose the fix code again.

Below are the patches I used to fix #1045 back then:

bravehorsie commented 5 years ago

@highsource You need to sign Eclipse ECA and sign off the commits for check to pass.

bravehorsie commented 5 years ago

@highsource

I'd like to add a test for my three schemas + catalog file first. Where should I put them in the project? I see almost none XJC tests (which is surprizing).

I don't have aged knowledge of JAXB history but I don't remember there were any tests other than for Ant tasks (xjc/src/test/java) ever. You could put your tests along there.

dschulten commented 10 months ago

One possible workaround: https://stackoverflow.com/questions/77465063/wsimport-xxx-is-already-defined-the-first-definition-appears-here