[testng] 04/355: testng-368 FWK005 parse may not be called while parsing Make org.testng.xml.XMLParser.m_saxParser private. ! Change on OpenAPI. And add method with synchronization.

Eugene Zhukov eugene-guest at moszumanska.debian.org
Tue Aug 18 10:19:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

eugene-guest pushed a commit to annotated tag OpenBSD
in repository testng.

commit 88e7c8811c34f1693e243685219dfb09f5811e23
Author: Vladislav Rassokhin <vladrassokhin at gmail.com>
Date:   Sat Apr 13 03:57:06 2013 +0400

    testng-368 FWK005 parse may not be called while parsing
    Make org.testng.xml.XMLParser.m_saxParser private. ! Change on OpenAPI.
    And add method with synchronization.
---
 src/main/java/org/testng/xml/ResultXMLParser.java |  2 +-
 src/main/java/org/testng/xml/SuiteXmlParser.java  |  2 +-
 src/main/java/org/testng/xml/XMLParser.java       | 15 +++++++++++++--
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/testng/xml/ResultXMLParser.java b/src/main/java/org/testng/xml/ResultXMLParser.java
index 8f4f31c..b93e7d0 100644
--- a/src/main/java/org/testng/xml/ResultXMLParser.java
+++ b/src/main/java/org/testng/xml/ResultXMLParser.java
@@ -40,7 +40,7 @@ public class ResultXMLParser extends XMLParser<Object> {
         loadClasses);
 
     try {
-      m_saxParser.parse(inputStream, handler);
+      parse(inputStream, handler);
 
       return null;
     }
diff --git a/src/main/java/org/testng/xml/SuiteXmlParser.java b/src/main/java/org/testng/xml/SuiteXmlParser.java
index 2a0202c..f746f82 100644
--- a/src/main/java/org/testng/xml/SuiteXmlParser.java
+++ b/src/main/java/org/testng/xml/SuiteXmlParser.java
@@ -14,7 +14,7 @@ public class SuiteXmlParser extends XMLParser<XmlSuite> {
     TestNGContentHandler contentHandler = new TestNGContentHandler(currentFile, loadClasses);
 
     try {
-      m_saxParser.parse(inputStream, contentHandler);
+      parse(inputStream, contentHandler);
 
       return contentHandler.getSuite();
     }
diff --git a/src/main/java/org/testng/xml/XMLParser.java b/src/main/java/org/testng/xml/XMLParser.java
index 264c4aa..6afb5c8 100644
--- a/src/main/java/org/testng/xml/XMLParser.java
+++ b/src/main/java/org/testng/xml/XMLParser.java
@@ -3,15 +3,18 @@ package org.testng.xml;
 import org.testng.TestNGException;
 import org.testng.internal.ClassHelper;
 import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
 
 import javax.xml.parsers.FactoryConfigurationError;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
+import java.io.IOException;
+import java.io.InputStream;
 
 abstract public class XMLParser<T> implements IFileParser<T> {
 
-  protected static SAXParser m_saxParser;
+  private final static SAXParser m_saxParser;
 
   static {
     SAXParserFactory spf = loadSAXParserFactory();
@@ -20,13 +23,21 @@ abstract public class XMLParser<T> implements IFileParser<T> {
       spf.setValidating(true);
     }
 
+    SAXParser parser = null;
     try {
-      m_saxParser = spf.newSAXParser();
+      parser = spf.newSAXParser();
     } catch (ParserConfigurationException e) {
       e.printStackTrace();
     } catch (SAXException e) {
       e.printStackTrace();
     }
+    m_saxParser = parser;
+  }
+
+  public void parse(InputStream is, DefaultHandler dh) throws SAXException, IOException {
+    synchronized (m_saxParser) {
+      m_saxParser.parse(is, dh);
+    }
   }
 
   /**

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git



More information about the pkg-java-commits mailing list