jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [2/4] jena git commit: JENA-1258: System init in NodeFactory. Make ARQConstants init-safe.
Date Wed, 09 Nov 2016 14:06:06 GMT
JENA-1258: System init in NodeFactory. Make ARQConstants init-safe.


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/782d2140
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/782d2140
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/782d2140

Branch: refs/heads/master
Commit: 782d214066e224ba553bcef2b626fefbcfd73113
Parents: f27f393
Author: Andy Seaborne <andy@apache.org>
Authored: Tue Nov 8 12:20:47 2016 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Tue Nov 8 12:29:43 2016 +0000

----------------------------------------------------------------------
 .../main/java/org/apache/jena/query/ARQ.java    |  4 ++++
 .../org/apache/jena/sparql/ARQConstants.java    | 25 +++++++++++---------
 .../java/org/apache/jena/sparql/SystemARQ.java  |  3 ++-
 .../main/java/org/apache/jena/graph/Node.java   |  5 +++-
 .../java/org/apache/jena/graph/NodeFactory.java |  3 +++
 5 files changed, 27 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/782d2140/jena-arq/src/main/java/org/apache/jena/query/ARQ.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/query/ARQ.java b/jena-arq/src/main/java/org/apache/jena/query/ARQ.java
index 9459290..5ded8ab 100644
--- a/jena-arq/src/main/java/org/apache/jena/query/ARQ.java
+++ b/jena-arq/src/main/java/org/apache/jena/query/ARQ.java
@@ -20,6 +20,7 @@ package org.apache.jena.query;
 
 import org.apache.jena.riot.RIOT ;
 import org.apache.jena.riot.system.RiotLib ;
+import org.apache.jena.sparql.ARQConstants;
 import org.apache.jena.sparql.SystemARQ ;
 import org.apache.jena.sparql.algebra.optimize.TransformOrderByDistinctApplication ;
 import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
@@ -576,6 +577,9 @@ public class ARQ
             }
             initialized = true ;
             JenaSystem.logLifecycle("ARQ.init - start") ;
+            // Force constants to be set.  This should be independent of other initialization
including jena core.
+            ARQConstants.getGlobalPrefixMap();
+            
             globalContext = defaultSettings() ;
             ARQMgt.init() ;         // After context and after PATH/NAME/VERSION/BUILD_DATE
are set
             MappingRegistry.addPrefixMapping(ARQ.arqSymbolPrefix, ARQ.arqParamNS) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/782d2140/jena-arq/src/main/java/org/apache/jena/sparql/ARQConstants.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/ARQConstants.java b/jena-arq/src/main/java/org/apache/jena/sparql/ARQConstants.java
index 2fdebe1..322f3e6 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/ARQConstants.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/ARQConstants.java
@@ -18,39 +18,42 @@
 
 package org.apache.jena.sparql;
 
-import org.apache.jena.datatypes.xsd.XSDDatatype ;
 import org.apache.jena.shared.PrefixMapping ;
 import org.apache.jena.shared.impl.PrefixMappingImpl ;
 import org.apache.jena.sparql.util.Symbol ;
-import org.apache.jena.system.JenaSystem ;
-import org.apache.jena.vocabulary.OWL ;
-import org.apache.jena.vocabulary.RDF ;
-import org.apache.jena.vocabulary.RDFS ;
 
 /**
  * Internal constants - configuration is in class ARQ
  */
 public class ARQConstants
 {
-    static { JenaSystem.init() ; }
-    
     /** The prefix of XQuery/Xpath functions and operator */
     public static final String fnPrefix = "http://www.w3.org/2005/xpath-functions#" ;
     
     /** The prefix of XQuery/Xpath functions and operator math: */
     public static final String mathPrefix = "http://www.w3.org/2005/xpath-functions/math#"
;
+
+    // Using explicit constants here makes ARQConstants safe to use during initialization.
+    // Otherwise it needs JenaSystem.init but the constants may be used during initialization
+    // which leads to problems depending in the order of initialization. 
+    //
+    // In
+    //   static final x = someFunctionCall();
+    // x is null until the class is initialized but class initialization can be cyclic 
+    // and is not always complete while another class is initializing and using this class.
+    // See also SystemARQ.allocSymbol
     
     /** RDF namespace prefix */
-    public static final String rdfPrefix = RDF.getURI() ;
+    public static final String rdfPrefix = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
// RDF.getURI()
 
     /** RDFS namespace prefix */
-    public static final String rdfsPrefix = RDFS.getURI() ;
+    public static final String rdfsPrefix = "http://www.w3.org/2000/01/rdf-schema#"; //RDFS.getURI()
;
 
     /** OWL namespace prefix */
-    public static final String owlPrefix = OWL.getURI() ;
+    public static final String owlPrefix = "http://www.w3.org/2002/07/owl#"; //OWL.getURI()
;
     
     /** XSD namespace prefix */
-    public static final String xsdPrefix = XSDDatatype.XSD+"#" ;
+    public static final String xsdPrefix = "http://www.w3.org/2001/XMLSchema#" ; //XSDDatatype.XSD+"#"
;
     
     /** The prefix of SPARQL functions and operator */
     public static final String fnSparql = "http://www.w3.org/ns/sparql#" ;

http://git-wip-us.apache.org/repos/asf/jena/blob/782d2140/jena-arq/src/main/java/org/apache/jena/sparql/SystemARQ.java
----------------------------------------------------------------------
diff --git a/jena-arq/src/main/java/org/apache/jena/sparql/SystemARQ.java b/jena-arq/src/main/java/org/apache/jena/sparql/SystemARQ.java
index 173e957..b607a20 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/SystemARQ.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/SystemARQ.java
@@ -143,13 +143,14 @@ public class SystemARQ
     }
 
     public static Symbol allocSymbol(String shortName) {
+        // This must work even if initialization is happening.
+        // Touching final constant explicit strings in ARQ is fine (compile time constants).
         if ( shortName.startsWith(ARQ.arqSymbolPrefix) )
             throw new ARQInternalErrorException("Symbol short name begins with the ARQ namespace
prefix: " + shortName) ;
         if ( shortName.startsWith("http:") )
             throw new ARQInternalErrorException("Symbol short name begins with http: " +
shortName) ;
         return SystemARQ.allocSymbol(ARQ.arqParamNS, shortName) ;
     }
-
     public static Symbol allocSymbol(String base, String shortName) {
         return Symbol.create(base + shortName) ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/782d2140/jena-core/src/main/java/org/apache/jena/graph/Node.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/graph/Node.java b/jena-core/src/main/java/org/apache/jena/graph/Node.java
index f44a308..492e1fc 100644
--- a/jena-core/src/main/java/org/apache/jena/graph/Node.java
+++ b/jena-core/src/main/java/org/apache/jena/graph/Node.java
@@ -22,6 +22,7 @@ import org.apache.jena.datatypes.RDFDatatype ;
 import org.apache.jena.graph.impl.LiteralLabel ;
 import org.apache.jena.shared.JenaException ;
 import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.system.JenaSystem;
 
 /**
     A Node has five subtypes: Node_Blank, Node_Anon, Node_URI,  
@@ -32,7 +33,9 @@ import org.apache.jena.shared.PrefixMapping ;
 */
 
 public abstract class Node {
-    
+
+    static { JenaSystem.init(); }
+
     final protected Object label;
     static final int THRESHOLD = 10000;
     

http://git-wip-us.apache.org/repos/asf/jena/blob/782d2140/jena-core/src/main/java/org/apache/jena/graph/NodeFactory.java
----------------------------------------------------------------------
diff --git a/jena-core/src/main/java/org/apache/jena/graph/NodeFactory.java b/jena-core/src/main/java/org/apache/jena/graph/NodeFactory.java
index 858ba27..ce4a09e 100644
--- a/jena-core/src/main/java/org/apache/jena/graph/NodeFactory.java
+++ b/jena-core/src/main/java/org/apache/jena/graph/NodeFactory.java
@@ -25,8 +25,11 @@ import org.apache.jena.datatypes.RDFDatatype ;
 import org.apache.jena.datatypes.TypeMapper ;
 import org.apache.jena.graph.impl.LiteralLabel ;
 import org.apache.jena.graph.impl.LiteralLabelFactory ;
+import org.apache.jena.system.JenaSystem;
 
 public class NodeFactory {
+    
+    static { JenaSystem.init(); }
 
     public static RDFDatatype getType(String s) {
         if ( s == null )


Mime
View raw message