You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2008/05/12 18:09:37 UTC

svn commit: r655544 - /incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java

Author: jmsnell
Date: Mon May 12 09:09:37 2008
New Revision: 655544

URL: http://svn.apache.org/viewvc?rev=655544&view=rev
Log:
https://issues.apache.org/jira/browse/ABDERA-155

Switch to lazy initialization of the various fields in the Abdera class to eliminate the likelihood of race conditions and NPE's in various environments

Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java?rev=655544&r1=655543&r2=655544&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java (original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/Abdera.java Mon May 12 09:09:37 2008
@@ -67,12 +67,12 @@
   }
   
   private final Configuration config;
-  private final Factory factory;
-  private final Parser parser;
-  private final XPath xpath;
-  private final ParserFactory parserFactory;
-  private final WriterFactory writerFactory;
-  private final Writer writer;
+  private Factory factory;
+  private Parser parser;
+  private XPath xpath;
+  private ParserFactory parserFactory;
+  private WriterFactory writerFactory;
+  private Writer writer;
   
   /**
    * Initialize using the default Abdera Configuration
@@ -87,12 +87,6 @@
    */
   public Abdera(Configuration config) {
     this.config = config;
-    factory = newFactory();
-    parser = newParser();
-    xpath = newXPath();
-    parserFactory = newParserFactory();
-    writerFactory = newWriterFactory();
-    writer = newWriter();
     IRI.preinit();  // initializes the IRI stuff to improve performance later
   }
   
@@ -147,7 +141,9 @@
    * 
    * @return The factory instance
    */
-  public Factory getFactory() {
+  public synchronized Factory getFactory() {
+    if (factory == null)
+      factory = newFactory();
     return factory;
   }
   
@@ -156,7 +152,9 @@
    * 
    * @return The parser instance
    */
-  public Parser getParser() {
+  public synchronized Parser getParser() {
+    if (parser == null)
+      parser = newParser();
     return parser;
   }
   
@@ -165,7 +163,9 @@
    * 
    * @return The XPath instance
    */
-  public XPath getXPath() {
+  public synchronized XPath getXPath() {
+    if (xpath == null)
+      xpath = newXPath();
     return xpath;
   }
   
@@ -176,7 +176,9 @@
    * 
    * @return The ParserFactory instance
    */
-  public ParserFactory getParserFactory() {
+  public synchronized ParserFactory getParserFactory() {
+    if (parserFactory == null)
+      parserFactory = newParserFactory();
     return parserFactory;
   }
   
@@ -187,7 +189,9 @@
    * 
    * @return The WriterFactory instance
    */
-  public WriterFactory getWriterFactory() {
+  public synchronized WriterFactory getWriterFactory() {
+    if (writerFactory == null)
+      writerFactory = newWriterFactory();
     return writerFactory;
   }
   
@@ -197,7 +201,9 @@
    * 
    * @return The default writer implementation
    */
-  public Writer getWriter() {
+  public synchronized Writer getWriter() {
+    if (writer == null)
+      writer = newWriter();
     return writer;
   }