Skip to content

Commit bc6efe7

Browse files
committed
Bug 36455727 - [36455326->24.09] include xsd processing silently fails with JDK22 with -Djdk.xml.jdkcatalog.resolve=strict
Remote remote.distribution on coherence-ce/main success, changes 108051, job.9.20240329183048.7048 [git-p4: depot-paths = "//dev/coherence-ce/main/": change = 108084]
1 parent 9ec09cd commit bc6efe7

File tree

5 files changed

+268
-8
lines changed

5 files changed

+268
-8
lines changed

prj/coherence-core/src/main/java/com/tangosol/run/xml/SaxParser.java

Lines changed: 212 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Copyright (c) 2000, 2020, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
5-
* http://oss.oracle.com/licenses/upl.
5+
* https://oss.oracle.com/licenses/upl.
66
*/
77
package com.tangosol.run.xml;
88

@@ -23,6 +23,8 @@
2323
import java.net.URLConnection;
2424

2525
import java.util.ArrayList;
26+
import java.util.Collections;
27+
import java.util.Iterator;
2628
import java.util.List;
2729

2830
import java.util.concurrent.atomic.AtomicBoolean;
@@ -38,6 +40,9 @@
3840
import javax.xml.validation.SchemaFactory;
3941
import javax.xml.validation.Validator;
4042

43+
import org.w3c.dom.ls.LSInput;
44+
import org.w3c.dom.ls.LSResourceResolver;
45+
4146
import org.xml.sax.AttributeList;
4247
import org.xml.sax.DocumentHandler;
4348
import org.xml.sax.ErrorHandler;
@@ -270,8 +275,17 @@ public void validateXsd(String sXml, XmlDocument xml)
270275
return;
271276
}
272277

273-
SchemaFactory schemaFactory = SchemaFactory
278+
ResourceResolver resolver = null;
279+
SchemaFactory schemaFactory = SchemaFactory
274280
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
281+
282+
if (s_fJdk22 && "strict".equalsIgnoreCase(System.getProperty("javax.xml.catalog.resolve")))
283+
{
284+
// specifying a custom resolver is a workaround for issue reported in OWLS-116652
285+
resolver = new ResourceResolver(this.getClass());
286+
schemaFactory.setResourceResolver(resolver);
287+
}
288+
275289
Schema schema = schemaFactory.newSchema(resolveSchemaSources(listSchemaURIs));
276290
Source source = new StreamSource(new StringReader(sXml));
277291
Validator validator = schema.newValidator();
@@ -301,6 +315,11 @@ public void validateXsd(String sXml, XmlDocument xml)
301315
validator.setErrorHandler(handler);
302316
validator.validate(source);
303317

318+
if (resolver != null)
319+
{
320+
resolver.closeStreams();
321+
}
322+
304323
// optimize error handling to report all errors
305324
// prior to failing; this is easier for user that
306325
// has multiple problems to config files.
@@ -746,10 +765,200 @@ public void fatalError(SAXParseException exception)
746765
private XmlElement m_current;
747766
}
748767

768+
// ----- inner class: Input ---------------------------------------------
769+
770+
/**
771+
* An LSInput implementation that is used when Java 22+ strict XML catalog resolve is enabled.
772+
* This class is required to work around the issue that is described in OWLS-116652
773+
*
774+
* @since 24.03
775+
*/
776+
public static class Input
777+
implements LSInput
778+
{
779+
// ----- constructors -----------------------------------------------
780+
781+
public Input(InputStream is, String publicId, String systemId)
782+
{
783+
this.is = is;
784+
this.publicId = publicId;
785+
this.systemId = systemId;
786+
}
787+
788+
// ----- LSInput interface ------------------------------------------
789+
790+
@Override
791+
public Reader getCharacterStream()
792+
{
793+
return null;
794+
}
795+
796+
@Override
797+
public void setCharacterStream(Reader characterStream)
798+
{
799+
}
800+
801+
@Override
802+
public InputStream getByteStream()
803+
{
804+
return this.is;
805+
}
806+
807+
@Override
808+
public void setByteStream(InputStream byteStream)
809+
{
810+
}
811+
812+
@Override
813+
public String getStringData()
814+
{
815+
return null;
816+
}
817+
818+
@Override
819+
public void setStringData(String stringData)
820+
{
821+
}
822+
823+
@Override
824+
public String getSystemId()
825+
{
826+
return this.systemId;
827+
}
828+
829+
@Override
830+
public void setSystemId(String systemId)
831+
{
832+
}
833+
834+
@Override
835+
public String getPublicId()
836+
{
837+
return this.publicId;
838+
}
839+
840+
@Override
841+
public void setPublicId(String publicId)
842+
{
843+
}
844+
@Override
845+
public String getBaseURI()
846+
{
847+
return null;
848+
}
849+
850+
@Override
851+
public void setBaseURI(String baseURI)
852+
{
853+
}
854+
855+
@Override
856+
public String getEncoding()
857+
{
858+
return null;
859+
}
860+
861+
@Override
862+
public void setEncoding(String encoding)
863+
{
864+
}
865+
866+
@Override
867+
public boolean getCertifiedText()
868+
{
869+
return false;
870+
}
871+
872+
@Override
873+
public void setCertifiedText(boolean certifiedText)
874+
{
875+
}
876+
877+
// ----- data members -----------------------------------------------
878+
879+
private InputStream is;
880+
881+
private String publicId;
882+
883+
private String systemId;
884+
}
885+
886+
// ----- inner class: ResourceResolver ----------------------------------
887+
888+
/**
889+
* An ResourceResolver implementation that is used when Java 22+ strict XML catalog resolve is enabled.
890+
* This class is required to work around the issue that is described in OWLS-116652
891+
*
892+
* @since 24.03
893+
*/
894+
public static class ResourceResolver
895+
implements LSResourceResolver
896+
{
897+
// ----- constructors -----------------------------------------------
898+
899+
ResourceResolver(Class<?> clazz)
900+
{
901+
this.clazz = clazz;
902+
}
903+
904+
// ----- LSResourceResolver interface -------------------------------
905+
906+
@Override
907+
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI)
908+
{
909+
InputStream is = this.clazz.getResourceAsStream("/" + systemId);
910+
911+
if (is == null)
912+
{
913+
Logger.warn("SaxParser.ResourceResolver.resolveResource: failed to resolve \"/" + systemId + " resolution: " + baseURI + "/" + systemId);
914+
return null;
915+
}
916+
else
917+
{
918+
this.streamsToClose.add(is);
919+
return new Input(is, publicId, systemId);
920+
}
921+
}
922+
923+
/**
924+
* Close all streams created by this resolver.
925+
*/
926+
void closeStreams()
927+
{
928+
Iterator iter = this.streamsToClose.iterator();
929+
930+
while (iter.hasNext())
931+
{
932+
InputStream is = (InputStream) iter.next();
933+
if (is != null)
934+
{
935+
try
936+
{
937+
is.close();
938+
}
939+
catch (IOException e)
940+
{
941+
}
942+
}
943+
}
944+
}
945+
946+
// ----- data members -----------------------------------------------
947+
948+
private List<InputStream> streamsToClose = Collections.synchronizedList(new ArrayList());
949+
950+
private Class<?> clazz;
951+
}
952+
749953
// ----- constants ------------------------------------------------------
750954

751955
/**
752956
* Record if resolved SaxParser supports JAXP 1.5 {@link XMLConstants#ACCESS_EXTERNAL_DTD} and {@link XMLConstants#ACCESS_EXTERNAL_SCHEMA} properties. Only report warning once if does not.
753957
*/
754958
private static final AtomicBoolean ATTEMPT_RESTRICT_EXTERNAL = new AtomicBoolean(true);
959+
960+
/**
961+
* True iff if jvm runtime is JDK 22 or higher.
962+
*/
963+
private static boolean s_fJdk22 = Runtime.version().feature() > 21;
755964
}

prj/coherence-testing-support/src/main/java/com/oracle/coherence/testing/bedrock/IllegalaccessProfile.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2023, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
55
* https://oss.oracle.com/licenses/upl.
@@ -54,15 +54,20 @@ public void onLaunching(
5454
if (jdk.getVersion() > 8)
5555
{
5656
// options introduced in jdk 9
57-
Freeforms jvmOptions = JvmOptions.include(
58-
"--add-opens=java.base/java.lang=ALL-UNNAMED");
57+
Freeforms jvmOptions = JvmOptions.include();
5958

6059
// Support was removed in JDK 17 so avoid warning message by not including in JDK 17 and greater
6160
if (jdk.getVersion() <= 16)
6261
{
6362
jvmOptions = jvmOptions.with(new Freeform("--illegal-access=" + m_sValue));
6463
}
6564

65+
if (jdk.getVersion() >= 22 && m_sValue.equals("strict"))
66+
{
67+
jvmOptions = JvmOptions.include("-Djavax.xml.catalog.resolve=strict",
68+
"-Djdk.xml.jdkcatalog.resolve=strict");
69+
}
70+
6671
Freeforms freeforms = optionsByType.get(Freeforms.class);
6772
for (Freeform freeform : freeforms)
6873
{

prj/pom.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,43 @@
992992
</build>
993993
</profile>
994994

995+
<profile>
996+
<id>test-catalog-resolve-strict</id>
997+
<properties>
998+
<!-- added properties *.resolve=strict to match jdk24 default -->
999+
<surefire.argLine>-Djavax.xml.catalog.resolve=strict -Djdk.xml.jdkcatalog.resolve=strict ${default.surefire.argLine}</surefire.argLine>
1000+
<failsafe.argLine>-Djavax.xml.catalog.resolve=strict -Djdk.xml.jdkcatalog.resolve=strict ${default.failsafe.argLine}</failsafe.argLine>
1001+
</properties>
1002+
<build>
1003+
<pluginManagement>
1004+
<plugins>
1005+
<plugin>
1006+
<groupId>org.apache.maven.plugins</groupId>
1007+
<artifactId>maven-surefire-plugin</artifactId>
1008+
<version>${maven.surefire.plugin.version}</version>
1009+
<configuration>
1010+
<systemPropertyVariables>
1011+
<bedrock.profile.illegalaccess>strict</bedrock.profile.illegalaccess>
1012+
<bedrock.profile.illegalaccess.classname>com.oracle.coherence.testing.bedrock.IllegalaccessProfile</bedrock.profile.illegalaccess.classname>
1013+
</systemPropertyVariables>
1014+
</configuration>
1015+
</plugin>
1016+
<plugin>
1017+
<groupId>org.apache.maven.plugins</groupId>
1018+
<artifactId>maven-failsafe-plugin</artifactId>
1019+
<version>${maven.failsafe.plugin.version}</version>
1020+
<configuration>
1021+
<systemPropertyVariables>
1022+
<bedrock.profile.illegalaccess>strict</bedrock.profile.illegalaccess>
1023+
<bedrock.profile.illegalaccess.classname>com.oracle.coherence.testing.bedrock.IllegalaccessProfile</bedrock.profile.illegalaccess.classname>
1024+
</systemPropertyVariables>
1025+
</configuration>
1026+
</plugin>
1027+
</plugins>
1028+
</pluginManagement>
1029+
</build>
1030+
</profile>
1031+
9951032
<profile>
9961033
<id>dependency-check</id>
9971034
<build>

prj/test/functional/xsd/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
3+
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
44
55
Licensed under the Universal Permissive License v 1.0 as shown at
66
https://oss.oracle.com/licenses/upl.
@@ -59,6 +59,11 @@
5959
<version>${project.version}</version>
6060
</dependency>
6161

62+
<dependency>
63+
<groupId>${coherence.group.id}</groupId>
64+
<artifactId>coherence-concurrent</artifactId>
65+
<version>${project.version}</version>
66+
</dependency>
6267
<!-- https://mvnrepository.com/artifact/xerces/xercesImpl -->
6368
<dependency>
6469
<groupId>xerces</groupId>

prj/test/functional/xsd/src/main/java/xsd/XsdValidationTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
33
*
44
* Licensed under the Universal Permissive License v 1.0 as shown at
55
* https://oss.oracle.com/licenses/upl.
@@ -106,6 +106,10 @@ public void testDefaultFiles()
106106
XmlValidator.validate("../../../coherence-core/src/main/resources/com/oracle/coherence/defaults/tangosol-coherence-override-eval.xml");
107107
XmlValidator.validate("../../../coherence-core/src/main/resources/com/oracle/coherence/defaults/tangosol-coherence-override-prod.xml");
108108
XmlValidator.validate("../../../coherence-core/src/main/resources/tangosol-coherence.xml");
109+
XmlValidator.validate("../../../coherence-core/src/main/resources/com/oracle/coherence/defaults/grpc-proxy-cache-config.xml");
110+
111+
XmlValidator.validate("../../../coherence-concurrent/src/main/resources/coherence-concurrent-config.xml");
112+
XmlValidator.validate("../../../coherence-concurrent/src/main/resources/coherence-concurrent-client-config.xml");
109113
}
110114

111115
/**

0 commit comments

Comments
 (0)