From 20c8ed39b3002b53efd89e427b580e92a08dd62f Mon Sep 17 00:00:00 2001 From: Lukas Jungmann Date: Mon, 9 Oct 2023 19:29:22 +0200 Subject: [PATCH] #1732: systemId resolution regression introduced in 2.3.4+ Signed-off-by: Lukas Jungmann --- .../src/docbook/jaxb-changelog.xml | 3 +++ .../xjc/api/impl/s2j/SchemaCompilerImpl.java | 22 +++------------- .../xjc/reader/internalizer/DOMForest.java | 25 +++---------------- .../xjc/reader/internalizer/Messages.java | 4 +-- .../internalizer/MessageBundle.properties | 5 +--- 5 files changed, 12 insertions(+), 47 deletions(-) diff --git a/jaxb-ri/docs/release-documentation/src/docbook/jaxb-changelog.xml b/jaxb-ri/docs/release-documentation/src/docbook/jaxb-changelog.xml index 1541a6793..f951a3df3 100644 --- a/jaxb-ri/docs/release-documentation/src/docbook/jaxb-changelog.xml +++ b/jaxb-ri/docs/release-documentation/src/docbook/jaxb-changelog.xml @@ -59,6 +59,9 @@ #1731: Incompatibility with namespace when marshalling WebFault with FaultInfo on call of WebService + + #1732: systemId resolution regression introduced in 2.3.4+ + #1736: xjc: postProcessModel is not called for DTDs diff --git a/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/api/impl/s2j/SchemaCompilerImpl.java b/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/api/impl/s2j/SchemaCompilerImpl.java index 95dbdc6e7..9f66bf1a8 100644 --- a/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/api/impl/s2j/SchemaCompilerImpl.java +++ b/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/api/impl/s2j/SchemaCompilerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -40,8 +40,6 @@ import org.glassfish.jaxb.core.unmarshaller.DOMScanner; import org.glassfish.jaxb.core.v2.util.XmlFactory; import com.sun.xml.xsom.XSSchemaSet; -import java.nio.file.Files; -import java.nio.file.Paths; import org.w3c.dom.Element; import org.w3c.dom.ls.LSInput; @@ -229,7 +227,8 @@ public LSInput resolveResource(String type, String namespaceURI, String publicId // XSOM passes the namespace URI to the publicID parameter. // we do the same here . InputSource is = opts.entityResolver.resolveEntity(namespaceURI, systemId == null ? "" : systemId); - return isExists(is) ? new LSInputSAXWrapper(is) : null; + if (is == null) return null; + return new LSInputSAXWrapper(is); } catch (SAXException | IOException e) { // TODO: is this sufficient? return null; @@ -309,21 +308,6 @@ public void fatalError(SAXParseException exception) { errorListener.fatalError(exception); } - private static boolean isExists(InputSource is) { - if (is == null) { - return false; - } - try { - URI uri = new URI(is.getSystemId()); - if ("file".equals(uri.getScheme())) { - return Files.exists(Paths.get(uri)); - } - } catch (URISyntaxException ex) { - //ignore, let it be handled by parser as is - } - return true; - } - /** * We use JAXP 1.3 to do a schema correctness check, but we know * it doesn't always work. So in case some people hit the problem, diff --git a/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/reader/internalizer/DOMForest.java b/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/reader/internalizer/DOMForest.java index bf37efe1e..e84a288fb 100644 --- a/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/reader/internalizer/DOMForest.java +++ b/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/reader/internalizer/DOMForest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -43,10 +43,6 @@ import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.net.URI; -import java.net.URISyntaxException; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.*; import static org.glassfish.jaxb.core.v2.util.XmlFactory.allowExternalAccess; @@ -267,26 +263,13 @@ public Document parse( String systemId, boolean root ) throws SAXException, IOEx InputSource is=null; // allow entity resolver to find the actual byte stream. - if( entityResolver!=null ) { - is = entityResolver.resolveEntity(null,systemId); + if (entityResolver != null) { + is = entityResolver.resolveEntity(null, systemId); } if (is == null) { is = new InputSource(systemId); - } else { - try { - URI uri = new URI(is.getSystemId()); - if ("file".equals(uri.getScheme())) { - if (!Files.exists(Paths.get(uri))) { - //resolved file does not exist, warn and let's continue with original systemId - errorReceiver.warning(null, Messages.format( - Messages.DOMFOREST_CATALOG_INVALID_ENTRY, is.getSystemId(), systemId)); - is = new InputSource(systemId); - } - } - } catch (URISyntaxException ex) { - //ignore, let it be handled by parser as is - } } + // but we still use the original system Id as the key. return parse( systemId, is, root ); } diff --git a/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/reader/internalizer/Messages.java b/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/reader/internalizer/Messages.java index 8a00ec050..6daf81fe9 100644 --- a/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/reader/internalizer/Messages.java +++ b/jaxb-ri/xjc/src/main/java/com/sun/tools/xjc/reader/internalizer/Messages.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -70,7 +70,5 @@ static String format( String property, Object... args ) { "ERR_GENERAL_SCHEMA_CORRECTNESS_ERROR"; static final String DOMFOREST_INPUTSOURCE_IOEXCEPTION = // arg:2 "DOMFOREST_INPUTSOURCE_IOEXCEPTION"; - static final String DOMFOREST_CATALOG_INVALID_ENTRY = // arg:2 - "DOMFOREST_CATALOG_INVALID_ENTRY"; } diff --git a/jaxb-ri/xjc/src/main/resources/com/sun/tools/xjc/reader/internalizer/MessageBundle.properties b/jaxb-ri/xjc/src/main/resources/com/sun/tools/xjc/reader/internalizer/MessageBundle.properties index 00d305320..6381f6d87 100644 --- a/jaxb-ri/xjc/src/main/resources/com/sun/tools/xjc/reader/internalizer/MessageBundle.properties +++ b/jaxb-ri/xjc/src/main/resources/com/sun/tools/xjc/reader/internalizer/MessageBundle.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved. # # This program and the accompanying materials are made available under the # terms of the Eclipse Distribution License v. 1.0, which is available at @@ -95,6 +95,3 @@ ERR_FILENAME_IS_NOT_URI = \ DOMFOREST_INPUTSOURCE_IOEXCEPTION = \ IOException thrown when processing "{0}". Exception: {1}. - -DOMFOREST_CATALOG_INVALID_ENTRY = \ - Catalog points to non-existent resource: "{0}". Trying to reach "{1}" directly.