Bug 61389 - Loading Stylesheet - 'xalan://java.lang.String:replaceAll' is not allowed when the secure processing feature is set to true.
Summary: Loading Stylesheet - 'xalan://java.lang.String:replaceAll' is not allowed whe...
Status: RESOLVED WORKSFORME
Alias: None
Product: Ant
Classification: Unclassified
Component: Optional Tasks (show other bugs)
Version: 1.10.1
Hardware: PC All
: P2 critical (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-08 03:56 UTC by Sarika Sinha
Modified: 2018-01-16 04:46 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sarika Sinha 2017-08-08 03:56:32 UTC
Eclipse Scripts fail to to load stylesheets with JDK 9 and Ant 1.10.1

javax.xml.transform.TransformerException: java.lang.RuntimeException: Use of the extension function 'xalan://java.lang.String:replaceAll' is not allowed when the secure processing feature is set to true.
	at org.apache.tools.ant.taskdefs.XSLTProcess.handleTransformationError(XSLTProcess.java:1449)
	at org.apache.tools.ant.taskdefs.XSLTProcess.process(XSLTProcess.java:856)
	at org.apache.tools.ant.taskdefs.XSLTProcess.execute(XSLTProcess.java:437)
	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
	at org.apache.tools.ant.Task.perform(Task.java:348)
	at org.apache.tools.ant.Target.execute(Target.java:435)
	at org.apache.tools.ant.Target.performTasks(Target.java:456)
	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
	at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
	at org.eclipse.ant.internal.launching.remote.EclipseSingleCheckExecutor.executeTargets(EclipseSingleCheckExecutor.java:34)
	at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
	at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:441)
	... 17 more
Caused by: javax.xml.transform.TransformerException: java.lang.RuntimeException: Use of the extension function 'xalan://java.lang.String:replaceAll' is not allowed when the secure processing feature is set to true.
	at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:790)
	at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:377)
	at org.apache.tools.ant.taskdefs.optional.TraXLiaison.transform(TraXLiaison.java:205)
	at org.apache.tools.ant.taskdefs.XSLTProcess.process(XSLTProcess.java:847)
	... 32 more
Caused by: java.lang.RuntimeException: Use of the extension function 'xalan://java.lang.String:replaceAll' is not allowed when the secure processing feature is set to true.
	at java.xml/com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary.runTimeError(BasisLibrary.java:1621)
	at java.xml/com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary.runTimeError(BasisLibrary.java:1625)
	at java.xml/com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary.unallowed_extension_functionF(BasisLibrary.java:453)
	at jdk.translet/die.verwandlung.JUNIT.JS$dash$escape()
	at jdk.translet/die.verwandlung.JUNIT.template$dot$5()
	at jdk.translet/die.verwandlung.JUNIT.applyTemplates()
	at jdk.translet/die.verwandlung.JUNIT.template$dot$0()
	at jdk.translet/die.verwandlung.JUNIT.applyTemplates()
	at jdk.translet/die.verwandlung.JUNIT.applyTemplates()
	at jdk.translet/die.verwandlung.JUNIT.transform()
	at java.xml/com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet.transform(AbstractTranslet.java:624)
	at java.xml/com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:783)
	... 35 more
Comment 1 Sarika Sinha 2017-08-08 03:57:36 UTC
Eclipse Bug -
https://bugs.eclipse.org/bugs/show_bug.cgi?id=506430
Comment 2 Stefan Bodewig 2017-08-09 09:56:07 UTC
We had a similar problem with our own unit tests, see bug 60060

http://ant.apache.org/manual/Tasks/style.html says:

> Note on XSLT extension functions: when using the default TraX implementation of the Java class library and a SecurityManager is active - e.g. when running from within an IDE - XSLT extension functions cannot be used as "secure processing" is active in Java 7 and above. Ant contains a special "hack" that allows XSLT extensions to be used in Java 7 and 8, but this hack fails for Java 9. If you want to use extensions like the redirect extension that are provided by the Java class library itself, you can allow them by enabling the feature http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions in Java 9 and above. If you need to use an extension function not provided by Java itself you can set the attribute jdk.xml.transform.extensionClassLoader to a classloader (reference to an Ant PATH-like structure).

Have you tried setting http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions  to true?
Comment 3 Sarika Sinha 2017-08-11 03:27:57 UTC
Will try out the option.
Comment 4 Stefan Bodewig 2017-09-03 15:21:35 UTC
any news?
Comment 5 Sarika Sinha 2017-11-28 05:35:05 UTC
Yes, we are able to with by using 
factory.setFeature("http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions", Boolean.TRUE); 

Can we use this for Java 8 as well as I see it mentioned on the help page that there was a hack for Java8 and Java7 which doesn't work now.
Comment 6 Stefan Bodewig 2017-11-28 15:55:27 UTC
The Java7/8 hack is still in place and used unless Ant detects it is running on Java9+. So you don't need to set the feature.

Unfortunately I assume trying to set the feature on Java8 may fail, so setting it unconditionally could cause problems on older JVMs. I'm not sure, though, the feature may as well simply get ignored and all would be well.

For org.apache.tools.ant.taskdefs.optional.junit.AggregateTransformer we only set it if we detect Java9 and are sure the XSLT processor is the one of the classlib and not a manually configured Xalan.
Comment 7 Sarika Sinha 2017-11-29 03:45:19 UTC
Thanks for the help.
Comment 8 Sarika Sinha 2018-01-11 07:08:08 UTC
When we run Eclipse in headless mode we are getting this exception - 
[xslt] Failed to load org.apache.xalan.processor.TransformerFactoryImpl via the configured classpath, will try Ant's classpath instead.
     [xslt] Failed to process null 

So problem I suppose is that java.xml/com.sun.org.apache.xalan.internal.xsltc.trax containing TransformerFactoryImpl in Java 9 is not exported in java.xml module.
So we tried adding --add-exports java.xml/com.sun.org.apache.xalan.internal.xsltc.trax=ALL-UNNAMED where we call Eclipse java program in headless mode.

Can you suggest where to set this attribute or how to provide this information to xslt?
Comment 9 Stefan Bodewig 2018-01-15 08:08:02 UTC
(In reply to Sarika Sinha from comment #8)
> When we run Eclipse in headless mode we are getting this exception - 
> [xslt] Failed to load org.apache.xalan.processor.TransformerFactoryImpl via
> the configured classpath, will try Ant's classpath instead.
>      [xslt] Failed to process null 

This means the class "org.apache.xalan.processor.TransformerFactoryImpl" hasn't been found. This seems to be the "name" attribute you've provided to the factory element of your xslt task.

This is not the class name of the transformer provided by JDK9 as far as I know. It is the name Apache Xalan would use when you add Xalan to your task's classpath.

> So problem I suppose is that
> java.xml/com.sun.org.apache.xalan.internal.xsltc.trax containing
> TransformerFactoryImpl in Java 9 is not exported in java.xml module.
> So we tried adding --add-exports
> java.xml/com.sun.org.apache.xalan.internal.xsltc.trax=ALL-UNNAMED where we
> call Eclipse java program in headless mode.

If you anted to use that, you must certainly use the correct package in the name attribute as well.

> Can you suggest where to set this attribute or how to provide this
> information to xslt?

My first suggestion is to not specify a name attribute for the factory at all but rather do with the default provided by the Jvaa runtime.

I must admit I haven't got any idea why things should be different in headless mode.
Comment 10 Sarika Sinha 2018-01-16 04:46:57 UTC
Thanks Stefan for the suggestion, Yes using the default factory worked out.