Skip to content

Commit 6daac1e

Browse files
committed
8343001: Adjust XSLT and XPath Extension Function Property
1 parent 68b1b94 commit 6daac1e

File tree

19 files changed

+275
-234
lines changed

19 files changed

+275
-234
lines changed

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/res/XSLTErrorResources.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -31,7 +31,7 @@
3131
* Array. You also need to update MAX_CODE for error strings
3232
* and MAX_WARNING for warnings ( Needed for only information
3333
* purpose )
34-
* @LastModified: May 2022
34+
* @LastModified: Dec 2024
3535
*/
3636
public class XSLTErrorResources extends ListResourceBundle
3737
{
@@ -1197,7 +1197,10 @@ public Object[][] getContents()
11971197
"Cannot set the feature ''{0}'' on this TransformerFactory."},
11981198

11991199
{ ER_EXTENSION_ELEMENT_NOT_ALLOWED_IN_SECURE_PROCESSING,
1200-
"Use of the extension element ''{0}'' is not allowed when the secure processing feature is set to true."},
1200+
"Use of the extension function ''{0}'' is not allowed when extension "
1201+
+ "functions are disabled by the secure processing feature or "
1202+
+ "the property ''jdk.xml.enableExtensionFunctions''. "
1203+
+ "To enable extension functions, set ''jdk.xml.enableExtensionFunctions'' to ''true''."},
12011204

12021205
{ ER_NAMESPACE_CONTEXT_NULL_NAMESPACE,
12031206
"Cannot get the prefix for a null namespace uri."},

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -62,7 +62,7 @@
6262
* @author Morten Jorgensen
6363
* @author Erwin Bolwidt <[email protected]>
6464
* @author Todd Miller
65-
* @LastModified: Nov 2017
65+
* @LastModified: Dec 2024
6666
*/
6767
class FunctionCall extends Expression {
6868

@@ -958,61 +958,58 @@ public boolean isExtension() {
958958
* after stripping its namespace or <code>null</code>
959959
* if no such methods exist.
960960
*/
961-
private List<Method> findMethods() {
961+
private List<Method> findMethods() throws TypeCheckError {
962962

963-
List<Method> result = null;
964-
final String namespace = _fname.getNamespace();
963+
List<Method> result = null;
964+
final String namespace = _fname.getNamespace();
965965

966-
if (_className != null && _className.length() > 0) {
966+
if (_className != null && _className.length() > 0) {
967967
final int nArgs = _arguments.size();
968968
try {
969969
if (_clazz == null) {
970970
final boolean isSecureProcessing = getXSLTC().isSecureProcessing();
971971
final boolean isExtensionFunctionEnabled = getXSLTC()
972972
.getFeature(JdkXmlFeatures.XmlFeature.ENABLE_EXTENSION_FUNCTION);
973973

974-
//Check if FSP and SM - only then process with loading
975-
if (namespace != null && isSecureProcessing
976-
&& isExtensionFunctionEnabled
977-
&& (namespace.startsWith(JAVA_EXT_XALAN)
978-
|| namespace.startsWith(JAVA_EXT_XSLTC)
979-
|| namespace.startsWith(JAVA_EXT_XALAN_OLD)
980-
|| namespace.startsWith(XALAN_CLASSPACKAGE_NAMESPACE))) {
981-
_clazz = getXSLTC().loadExternalFunction(_className);
974+
// the property has the precedence
975+
if (isExtensionFunctionEnabled) {
976+
if (getXSLTC().hasExtensionClassLoader()) {
977+
_clazz = getXSLTC().loadExternalFunction(_className);
978+
} else {
979+
_clazz = ObjectFactory.findProviderClass(_className, true);
980+
}
981+
if (_clazz == null) {
982+
final ErrorMsg msg
983+
= new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
984+
getParser().reportError(Constants.ERROR, msg);
985+
return null;
986+
}
982987
} else {
983-
_clazz = ObjectFactory.findProviderClass(_className, true);
988+
throw new TypeCheckError(ErrorMsg.UNSUPPORTED_EXT_FUNC_ERR, _className);
984989
}
985-
986-
if (_clazz == null) {
987-
final ErrorMsg msg =
988-
new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
989-
getParser().reportError(Constants.ERROR, msg);
990990
}
991-
}
992-
993-
final String methodName = _fname.getLocalPart();
994-
final Method[] methods = _clazz.getMethods();
995-
996-
for (int i = 0; i < methods.length; i++) {
997-
final int mods = methods[i].getModifiers();
998-
// Is it public and same number of args ?
999-
if (Modifier.isPublic(mods)
1000-
&& methods[i].getName().equals(methodName)
1001-
&& methods[i].getParameterTypes().length == nArgs)
1002-
{
1003-
if (result == null) {
1004-
result = new ArrayList<>();
1005-
}
1006-
result.add(methods[i]);
991+
992+
final String methodName = _fname.getLocalPart();
993+
final Method[] methods = _clazz.getMethods();
994+
995+
for (int i = 0; i < methods.length; i++) {
996+
final int mods = methods[i].getModifiers();
997+
// Is it public and same number of args ?
998+
if (Modifier.isPublic(mods)
999+
&& methods[i].getName().equals(methodName)
1000+
&& methods[i].getParameterTypes().length == nArgs) {
1001+
if (result == null) {
1002+
result = new ArrayList<>();
1003+
}
1004+
result.add(methods[i]);
1005+
}
10071006
}
1008-
}
1009-
}
1010-
catch (ClassNotFoundException e) {
1011-
final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
1012-
getParser().reportError(Constants.ERROR, msg);
1007+
} catch (ClassNotFoundException e) {
1008+
final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
1009+
getParser().reportError(Constants.ERROR, msg);
10131010
}
1014-
}
1015-
return result;
1011+
}
1012+
return result;
10161013
}
10171014

10181015
/**

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -57,7 +57,7 @@
5757
* @author G. Todd Miller
5858
* @author Morten Jorgensen
5959
* @author John Howard ([email protected])
60-
* @LastModified: Jan 2022
60+
* @LastModified: Dec 2024
6161
*/
6262
public final class XSLTC {
6363

@@ -291,6 +291,10 @@ private void setExternalExtensionFunctions(String name, Class<?> clazz) {
291291
}
292292
}
293293

294+
boolean hasExtensionClassLoader() {
295+
return _extensionClassLoader != null;
296+
}
297+
294298
/*
295299
* Function loads an external extension function.
296300
* The filtering of function types (external,internal) takes place in FunctionCall class

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMessages.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
/**
2626
* @author Morten Jorgensen
27-
* @LastModified: Nov 2024
27+
* @LastModified: Dec 2024
2828
*/
2929
public class ErrorMessages extends ListResourceBundle {
3030

@@ -552,6 +552,15 @@ public Object[][] getContents()
552552
{ErrorMsg.DATA_CONVERSION_ERR,
553553
"Cannot convert data-type ''{0}'' to ''{1}''."},
554554

555+
/*
556+
* Note to translators: property name "jdk.xml.enableExtensionFunctions"
557+
* and value "true" should not be translated.
558+
*/
559+
{ErrorMsg.UNSUPPORTED_EXT_FUNC_ERR,
560+
"Use of the extension function ''{0}'' is not allowed when extension "
561+
+ "functions are disabled by the secure processing feature or "
562+
+ "the property ''jdk.xml.enableExtensionFunctions''. "
563+
+ "To enable extension functions, set ''jdk.xml.enableExtensionFunctions'' to ''true''."},
555564
/*
556565
* Note to translators: "Templates" is a Java class name that should
557566
* not be translated.

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMsg.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @author G. Todd Miller
3434
* @author Erwin Bolwidt <[email protected]>
3535
* @author Morten Jorgensen
36-
* @LastModified: Nov 2024
36+
* @LastModified: Dec 2024
3737
*/
3838
public final class ErrorMsg {
3939

@@ -105,6 +105,7 @@ public final class ErrorMsg {
105105
public static final String ATTR_VAL_TEMPLATE_ERR = "ATTR_VAL_TEMPLATE_ERR";
106106
public static final String UNKNOWN_SIG_TYPE_ERR = "UNKNOWN_SIG_TYPE_ERR";
107107
public static final String DATA_CONVERSION_ERR = "DATA_CONVERSION_ERR";
108+
public static final String UNSUPPORTED_EXT_FUNC_ERR = "UNSUPPORTED_EXT_FUNC_ERR";
108109

109110
// JAXP/TrAX error messages
110111
public static final String NO_TRANSLET_CLASS_ERR = "NO_TRANSLET_CLASS_ERR";

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/runtime/ErrorMessages.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
2-
* reserved comment block
3-
* DO NOT REMOVE OR ALTER!
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
43
*/
54
/*
65
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -25,6 +24,7 @@
2524

2625
/**
2726
* @author Morten Jorgensen
27+
* @LastModified: Dec 2024
2828
*/
2929
public class ErrorMessages extends ListResourceBundle {
3030

@@ -275,10 +275,16 @@ public Object[][] getContents()
275275
"An attribute whose value must be an NCName had the value ''{0}''"},
276276

277277
{BasisLibrary.UNALLOWED_EXTENSION_FUNCTION_ERR,
278-
"Use of the extension function ''{0}'' is not allowed when the secure processing feature is set to true."},
278+
"Use of the extension function ''{0}'' is not allowed when extension "
279+
+ "functions are disabled by the secure processing feature or "
280+
+ "the property ''jdk.xml.enableExtensionFunctions''. "
281+
+ "To enable extension functions, set ''jdk.xml.enableExtensionFunctions'' to ''true''."},
279282

280283
{BasisLibrary.UNALLOWED_EXTENSION_ELEMENT_ERR,
281-
"Use of the extension element ''{0}'' is not allowed when the secure processing feature is set to true."},
284+
"Use of the extension function ''{0}'' is not allowed when extension "
285+
+ "functions are disabled by the secure processing feature or "
286+
+ "the property ''jdk.xml.enableExtensionFunctions''. "
287+
+ "To enable extension functions, set ''jdk.xml.enableExtensionFunctions'' to ''true''."},
282288
};
283289
}
284290

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
import jdk.xml.internal.JdkXmlUtils;
7676
import jdk.xml.internal.JdkProperty.ImplPropMap;
7777
import jdk.xml.internal.JdkProperty.State;
78-
import jdk.xml.internal.SecuritySupport;
7978
import jdk.xml.internal.TransformErrorListener;
8079
import jdk.xml.internal.XMLSecurityManager;
8180
import org.xml.sax.InputSource;
@@ -88,7 +87,7 @@
8887
* @author G. Todd Miller
8988
* @author Morten Jorgensen
9089
* @author Santiago Pericas-Geertsen
91-
* @LastModified: Nov 2024
90+
* @LastModified: Dec 2024
9291
*/
9392
public class TransformerFactoryImpl
9493
extends SAXTransformerFactory implements SourceLoader
@@ -216,7 +215,7 @@ public PIParamWrapper(String media, String title, String charset) {
216215
/**
217216
* <p>State of secure processing feature.</p>
218217
*/
219-
private boolean _isNotSecureProcessing = true;
218+
private boolean _isNotSecureProcessing = false;
220219
/**
221220
* <p>State of secure mode.</p>
222221
*/

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -100,7 +100,7 @@
100100
* @author Morten Jorgensen
101101
* @author G. Todd Miller
102102
* @author Santiago Pericas-Geertsen
103-
* @LastModified: July 2023
103+
* @LastModified: Dec 2024
104104
*/
105105
public final class TransformerImpl extends Transformer
106106
implements DOMCache
@@ -206,7 +206,7 @@ public final class TransformerImpl extends Transformer
206206
/**
207207
* State of the secure processing feature.
208208
*/
209-
private boolean _isSecureProcessing = false;
209+
private boolean _isSecureProcessing = true;
210210

211211
/**
212212
* Indicates whether 3rd party parser may be used to override the system-default
@@ -292,6 +292,7 @@ protected TransformerImpl(Translet translet, Properties outputProperties,
292292
_propertiesClone = (Properties) _properties.clone();
293293
_indentNumber = indentNumber;
294294
_tfactory = tfactory;
295+
_isSecureProcessing = _tfactory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
295296
_overrideDefaultParser = _tfactory.overrideDefaultParser();
296297
_accessExternalDTD = (String)_tfactory.getAttribute(XMLConstants.ACCESS_EXTERNAL_DTD);
297298
_securityManager = (XMLSecurityManager)_tfactory.getAttribute(JdkConstants.SECURITY_MANAGER);

src/java.xml/share/classes/jdk/xml/internal/JdkXmlFeatures.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static enum XmlFeature {
5252
* function is disabled.
5353
*/
5454
ENABLE_EXTENSION_FUNCTION(ImplPropMap.ENABLEEXTFUNC, null, null, true,
55-
null, null, true, false, true, true),
55+
null, null, false, false, true, true),
5656
/**
5757
* The {@link javax.xml.XMLConstants.USE_CATALOG} feature.
5858
* FSP: USE_CATALOG is not enforced by FSP.
@@ -382,13 +382,7 @@ public int getIndex(String propertyName) {
382382
*/
383383
private void readSystemProperties() {
384384
for (XmlFeature feature : XmlFeature.values()) {
385-
if (!getSystemProperty(feature, feature.systemProperty())) {
386-
//if system property is not found, try the older form if any
387-
String oldName = feature.systemPropertyOld();
388-
if (oldName != null) {
389-
getSystemProperty(feature, oldName);
390-
}
391-
}
385+
getSystemProperty(feature, feature.systemProperty());
392386
}
393387
}
394388

@@ -402,6 +396,11 @@ private void readSystemProperties() {
402396
private boolean getSystemProperty(XmlFeature feature, String sysPropertyName) {
403397
try {
404398
String value = System.getProperty(sysPropertyName);
399+
if (value == null && feature.systemPropertyOld() != null) {
400+
// legacy system property
401+
value = System.getProperty(feature.systemPropertyOld());
402+
}
403+
405404
if (value != null && !value.isEmpty()) {
406405
setFeature(feature, State.SYSTEMPROPERTY, Boolean.parseBoolean(value));
407406
return true;

src/java.xml/share/conf/jaxp.properties

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@
5757
# Extension Functions:
5858
#
5959
# This property determines whether XSLT and XPath extension functions are allowed.
60-
# The value type is boolean and the default value is true (allowing
61-
# extension functions). The following entry overrides the default value and
62-
# disallows extension functions:
60+
# The value type is boolean and the default value is false (disallowing
61+
# extension functions).
6362
#
64-
# jdk.xml.enableExtensionFunctions=false
63+
jdk.xml.enableExtensionFunctions=false
6564
#
6665
#
6766
# Overriding the default parser:

0 commit comments

Comments
 (0)