8150145: javax/xml/jaxp/unittest/common/TransformationWarningsTest.java and ValidationWarningsTest.java failed intermittently without any error message
Reviewed-by: joehw, clanger
--- a/jaxp/test/ProblemList.txt Wed Aug 31 14:33:23 2016 -0700
+++ b/jaxp/test/ProblemList.txt Thu Sep 01 17:12:12 2016 +0300
@@ -24,7 +24,3 @@
###########################################################################
javax/xml/jaxp/isolatedjdk/catalog/PropertiesTest.sh 8147431 generic-all
-
-javax/xml/jaxp/unittest/common/TransformationWarningsTest.java 8150145 generic-all
-
-javax/xml/jaxp/unittest/common/ValidationWarningsTest.java 8150145 generic-all
--- a/jaxp/test/javax/xml/jaxp/unittest/common/TransformationWarningsTest.java Wed Aug 31 14:33:23 2016 -0700
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/TransformationWarningsTest.java Thu Sep 01 17:12:12 2016 +0300
@@ -42,12 +42,13 @@
* @test
* @bug 8144593
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
+ * @compile -XDignore.symbol.file TestSAXDriver.java
* @run testng/othervm -DrunSecMngr=true common.TransformationWarningsTest
* @run testng/othervm common.TransformationWarningsTest
* @summary Check that warnings about unsupported properties from parsers
* are suppressed during the transformation process.
*/
-@Listeners({jaxp.library.BasePolicy.class})
+@Listeners({jaxp.library.BasePolicy.class, jaxp.library.InternalAPIPolicy.class})
public class TransformationWarningsTest extends WarningsTestBase {
@BeforeClass
@@ -80,7 +81,12 @@
Source xslsrc = new StreamSource(new StringReader(xsl));
// Create factory and transformer
- TransformerFactory tf = TransformerFactory.newInstance();
+ TransformerFactory tf;
+ // newTransformer() method doc states that different transformer
+ // factories can be used concurrently by different Threads.
+ synchronized (TransformerFactory.class) {
+ tf = TransformerFactory.newInstance();
+ }
Transformer t = tf.newTransformer(xslsrc);
// Set URI Resolver to return the newly constructed xml
--- a/jaxp/test/javax/xml/jaxp/unittest/common/ValidationWarningsTest.java Wed Aug 31 14:33:23 2016 -0700
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/ValidationWarningsTest.java Thu Sep 01 17:12:12 2016 +0300
@@ -46,6 +46,7 @@
* @bug 8144593
* @key intermittent
* @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
+ * @compile -XDignore.symbol.file TestSAXDriver.java
* @run testng/othervm -DrunSecMngr=true common.ValidationWarningsTest
* @run testng/othervm common.ValidationWarningsTest
* @summary Check that warnings about unsupported properties from SAX
--- a/jaxp/test/javax/xml/jaxp/unittest/common/WarningsTestBase.java Wed Aug 31 14:33:23 2016 -0700
+++ b/jaxp/test/javax/xml/jaxp/unittest/common/WarningsTestBase.java Thu Sep 01 17:12:12 2016 +0300
@@ -23,11 +23,15 @@
package common;
+import static jaxp.library.JAXPTestUtilities.runWithAllPerm;
+
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.lang.Thread.UncaughtExceptionHandler;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -58,25 +62,27 @@
PrintStream defStdErr = System.err;
//Set new byte array stream as standard error stream
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(5000);
- System.setErr(new PrintStream(byteStream));
+ runWithAllPerm(() -> System.setErr(new PrintStream(byteStream)));
//Execute multiple TestWorker tasks
for (int id = 0; id < THREADS_COUNT; id++) {
EXECUTOR.execute(new TestWorker(id));
}
//Initiate shutdown of previously submitted task
- EXECUTOR.shutdown();
+ runWithAllPerm(EXECUTOR::shutdown);
//Wait for termination of submitted tasks
if (!EXECUTOR.awaitTermination(THREADS_COUNT, TimeUnit.SECONDS)) {
//If not all tasks terminates during the time out force them to shutdown
- EXECUTOR.shutdownNow();
+ runWithAllPerm(EXECUTOR::shutdownNow);
}
//Restore default standard error stream
- System.setErr(defStdErr);
+ runWithAllPerm(() -> System.setErr(defStdErr));
//Print tasks stderr output
String errContent = byteStream.toString();
System.out.println("Standard error output content:");
System.out.println(errContent);
- //Check tasks stderr output for quatity of warning messages
+ //Check if uncaught exceptions were observed by one or more threads
+ Assert.assertFalse(uncaughtExceptions);
+ //Check tasks stderr output for quantity of warning messages
Assert.assertTrue(warningPrintedOnce(XMLConstants.ACCESS_EXTERNAL_DTD, errContent));
Assert.assertTrue(warningPrintedOnce(ENT_EXP_PROPERTY, errContent));
Assert.assertTrue(warningPrintedOnce(XMLConstants.FEATURE_SECURE_PROCESSING, errContent));
@@ -123,6 +129,25 @@
}
}
+ // Thread factory that handles uncaughtExceptions and prints them
+ // to stdout instead of stderr.
+ private static class TestThreadFactory implements ThreadFactory {
+
+ public Thread newThread(final Runnable r) {
+ Thread t = Executors.defaultThreadFactory().newThread(r);
+ t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
+ @Override
+ public void uncaughtException(Thread t, Throwable thr) {
+ thr.printStackTrace(System.out);
+ uncaughtExceptions = true;
+ }
+ });
+ return t;
+ }
+ }
+
+ //Flag that indicates if one or more threads from thread pool caught unhandled exception
+ private static boolean uncaughtExceptions = false;
//Entity expansion limit property name
private static final String ENT_EXP_PROPERTY = "http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit";
//Number of simultaneous test threads
@@ -130,7 +155,7 @@
//Number of iterations per one thread
private static final int ITERATIONS_PER_THREAD = 4;
//Test thread pool
- private static final ExecutorService EXECUTOR = Executors.newCachedThreadPool();
- //Cyclic barrier for threads startup synchronisation
+ private static final ExecutorService EXECUTOR = Executors.newCachedThreadPool(new TestThreadFactory());
+ //Cyclic barrier for threads startup synchronization
private static final CyclicBarrier BARRIER = new CyclicBarrier(THREADS_COUNT);
}