Skip to content

Commit

Permalink
#52382: <xslt> with redirect broken on JDK 7 when a SecurityManager i…
Browse files Browse the repository at this point in the history
…s set.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1222724 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jglick committed Dec 23, 2011
1 parent 4dab12f commit fe829a9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
3 changes: 2 additions & 1 deletion WHATSNEW
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Fixed bugs:
Bugzilla Report 51049.

* <junitreport> did not work in embedded environments on JDK 7.
Bugzilla Report 51668.
Nor did <xslt> when using Xalan redirects.
Bugzilla Report 51668, 52382.

* Encoding of unicode escape sequences by the property file task
Bugzilla Report 50515.
Expand Down
17 changes: 6 additions & 11 deletions src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,12 @@ private TransformerFactory getFactory() throws BuildException {
}
}

if (Boolean.TRUE.equals(DISABLE_SECURE_PROCESSING.get())) {
try {
Field _isNotSecureProcessing = tfactory.getClass().getDeclaredField("_isNotSecureProcessing");
_isNotSecureProcessing.setAccessible(true);
_isNotSecureProcessing.set(tfactory, Boolean.TRUE);
} catch (Exception x) {
try { // #51668, #52382
Field _isNotSecureProcessing = tfactory.getClass().getDeclaredField("_isNotSecureProcessing");
_isNotSecureProcessing.setAccessible(true);
_isNotSecureProcessing.set(tfactory, Boolean.TRUE);
} catch (Exception x) {
if (project != null) {
project.log(x.toString(), Project.MSG_DEBUG);
}
}
Expand All @@ -443,11 +443,6 @@ private TransformerFactory getFactory() throws BuildException {
}
return tfactory;
}
/**
* Not part of any stable API.
* @see #51668
*/
public static final ThreadLocal/*<Boolean>*/ DISABLE_SECURE_PROCESSING = new ThreadLocal();


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,10 @@ public void transform() throws BuildException {
paramx.setName("output.dir");
paramx.setExpression(toDir.getAbsolutePath());
final long t0 = System.currentTimeMillis();
TraXLiaison.DISABLE_SECURE_PROCESSING.set(Boolean.TRUE);
try {
xsltTask.execute();
} catch (Exception e) {
throw new BuildException("Errors while applying transformations: " + e.getMessage(), e);
} finally {
TraXLiaison.DISABLE_SECURE_PROCESSING.set(null);
}
final long dt = System.currentTimeMillis() - t0;
task.log("Transform time: " + dt + "ms");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.util.JAXPUtils;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.security.Permission;

import junit.framework.AssertionFailedError;

Expand Down Expand Up @@ -65,11 +68,26 @@ public void testXalan2Redirect() throws Exception {
liaison.setStylesheet(xsl);
File out = new File("xalan2-redirect-out-dummy.tmp");
File in = getFile("/taskdefs/optional/xsltliaison-in.xsl");
ClassLoader orig = Thread.currentThread().getContextClassLoader();
try {
liaison.addParam("xalan-version", "2");
// Use the JRE's Xerces, not lib/optional/xerces.jar:
Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) {
public InputStream getResourceAsStream(String name) {
if (name.startsWith("META-INF/services/")) {
// work around JAXP #6723276 in JDK 6
return new ByteArrayInputStream(new byte[0]);
}
return super.getResourceAsStream(name);
}
});
// Tickle #52382:
System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}});
liaison.transform(in, out);
} finally {
out.delete();
Thread.currentThread().setContextClassLoader(orig);
System.setSecurityManager(null);
}
}

Expand Down

0 comments on commit fe829a9

Please sign in to comment.