[ 
https://issues.apache.org/jira/browse/JENA-1039?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14939169#comment-14939169
 ] 

Stian Soiland-Reyes commented on JENA-1039:
-------------------------------------------

Avoiding this inter-twingled static initialization code is why people invented 
Spring.. This is screaming for further refactoring..  :)  

So it's partially caused by InitJenaCore just calling OWL.getURI() (which the 
compiler figures out is just a String constant) rather than say 
OWL.FULL_LANG.getURI() - thus the individual constants of OWL from OWL.m_model 
has not necessarily been created yet during class initialization.

The biggest problem in that OWL requires ModelFactory, that also forces 
JenaSystem.init().  Thus both OWL and ModelFactory must participate in 
initialization.

This simple test highlights the problem - if run standalone:

{code}
package org.apache.jena.vocabulary.test;

import static org.junit.Assert.assertEquals;

import org.apache.jena.vocabulary.OWL;
import org.junit.Test;

// Deliberately not part of the test case 
public class TestOWLConstruction {
        
        @Test
        public void testName() throws Exception {
                assertEquals("http://www.w3.org/2002/07/owl#sameAs";, 
OWL.sameAs.getURI());
        }
}
{code}

Changing InitJenaCore to call OWL.init() does not help:

{code}
        public static void init() {
        System.out.println(m_model != null);
    }
{code}

which prints out "false". Obviously one can make  m_model non-final and set it 
from final if null - but that does not mean that the rest of OWL.java has been 
initialized for code which first Jena thing they do is the equivalent of 
OWL.FULL_LANG.getURI().  And obviously we don't want the public constants to be 
non-final! :)

The ProfileRegistry can be changed to look up String constants instead, which 
might help as a workaround. But I'm not very convinced by cross-module class 
initialization dependencies like what has been introduced now.


> Race condition on OWL.java class constructor
> --------------------------------------------
>
>                 Key: JENA-1039
>                 URL: https://issues.apache.org/jira/browse/JENA-1039
>             Project: Apache Jena
>          Issue Type: Bug
>          Components: ARQ, Core
>    Affects Versions: Jena 3.0.1
>         Environment: stain@biggie:~/src/jena/jena-arq$ mvn -version
> Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 
> 2015-04-22T12:57:37+01:00)
> Maven home: /home/stain/software/maven
> Java version: 1.8.0_45-internal, vendor: Oracle Corporation
> Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
> Default locale: en_GB, platform encoding: UTF-8
> OS name: "linux", version: "3.16.0-49-generic", arch: "amd64", family: "unix"
>            Reporter: Stian Soiland-Reyes
>
> latest master (fa26eefe0f55ae26cde88e7a4945bc9349a7e5f5) fails mvn clean 
> install on jena-arq:
> {code}
> [INFO] Compiling 284 source files to 
> /home/stain/src/jena/jena-arq/target/test-classes
> [WARNING] 
> /home/stain/src/jena/jena-arq/src/test/java/org/apache/jena/sparql/graph/TestGraphUnionRead.java:
>  
> /home/stain/src/jena/jena-arq/src/test/java/org/apache/jena/sparql/graph/TestGraphUnionRead.java
>  
> uses unchecked or unsafe operations.
> [WARNING] 
> /home/stain/src/jena/jena-arq/src/test/java/org/apache/jena/sparql/graph/TestGraphUnionRead.java:
>  Recompile with -Xlint:unchecked for details.
> [INFO] 
> [INFO] --- maven-surefire-plugin:2.17:test (default-test) @ jena-arq ---
> [INFO] Surefire report directory: 
> /home/stain/src/jena/jena-arq/target/surefire-reports
> -------------------------------------------------------
>  T E S T S
> -------------------------------------------------------
> Running org.apache.jena.sparql.TC_Scripted
> Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.495 sec <<< 
> FAILURE! - in org.apache.jena.sparql.TC_Scripted
> initializationError(org.apache.jena.sparql.TC_Scripted)  Time elapsed: 0.006 
> sec  <<< ERROR!
> java.lang.ExceptionInInitializerError: null
>         at 
> org.apache.jena.ontology.ProfileRegistry.<clinit>(ProfileRegistry.java:43)
>         at 
> org.apache.jena.ontology.OntModelSpec.<clinit>(OntModelSpec.java:49)
>         at 
> org.apache.jena.assembler.assemblers.OntModelAssembler.<clinit>(OntModelAssembler.java:56)
>         at 
> org.apache.jena.assembler.ConstAssembler.ontModel(ConstAssembler.java:59)
>         at 
> org.apache.jena.assembler.ConstAssembler.general(ConstAssembler.java:147)
>         at 
> org.apache.jena.sparql.core.assembler.AssemblerUtils.init(AssemblerUtils.java:59)
>         at org.apache.jena.query.ARQ.init(ARQ.java:567)
>         at org.apache.jena.sparql.system.InitARQ.start(InitARQ.java:29)
>         at 
> org.apache.jena.system.JenaSystem.lambda$init$44(JenaSystem.java:113)
>         at 
> org.apache.jena.system.JenaSystem$$Lambda$4/1415157681.accept(Unknown Source)
>         at java.util.ArrayList.forEach(ArrayList.java:1249)
>         at org.apache.jena.system.JenaSystem.forEach(JenaSystem.java:178)
>         at org.apache.jena.system.JenaSystem.forEach(JenaSystem.java:155)
>         at org.apache.jena.system.JenaSystem.init(JenaSystem.java:110)
>         at 
> org.apache.jena.rdf.model.ModelFactory.<clinit>(ModelFactory.java:49)
>         at org.apache.jena.vocabulary.OWL.<clinit>(OWL.java:36)
>         at org.apache.jena.sparql.graph.NodeConst.<clinit>(NodeConst.java:45)
>         at org.apache.jena.sparql.expr.NodeValue.<clinit>(NodeValue.java:126)
>         at org.apache.jena.sparql.TC_Scripted.<init>(TC_Scripted.java:40)
>         at org.apache.jena.sparql.TC_Scripted.suite(TC_Scripted.java:30)
> Running org.apache.jena.sparql.resultset.TS_ResultSet
> Tests run: 77, Failures: 0, Errors: 36, Skipped: 0, Time elapsed: 0.186 sec 
> <<< FAILURE! - in org.apache.jena.sparql.resultset.TS_ResultSet
> test_RS_1(org.apache.jena.sparql.resultset.TestResultSet)  Time elapsed: 0.02 
> sec  <<< ERROR!
> java.lang.NoClassDefFoundError: Could not initialize class 
> org.apache.jena.rdf.model.ModelFactory
>         at 
> org.apache.jena.sparql.graph.GraphFactory.makeJenaDefaultModel(GraphFactory.java:72)
>         at 
> org.apache.jena.sparql.resultset.XMLInputStAX.worker(XMLInputStAX.java:143)
>         at 
> org.apache.jena.sparql.resultset.XMLInputStAX.<init>(XMLInputStAX.java:104)
>         at org.apache.jena.sparql.resultset.XMLInput.make(XMLInput.java:81)
>         at org.apache.jena.sparql.resultset.XMLInput.fromXML(XMLInput.java:39)
>         at org.apache.jena.sparql.resultset.XMLInput.fromXML(XMLInput.java:34)
>         at 
> org.apache.jena.query.ResultSetFactory.fromXML(ResultSetFactory.java:308)
>         at 
> org.apache.jena.sparql.resultset.TestResultSet.test_RS_1(TestResultSet.java:74)
> {code}
> Every test in jena-arq fails with a similar java.lang.NoClassDefFoundError:
> I assume this is caused by the initial ExceptionInInitializerError from 
> (ProfileRegistry - relating to the recent JenaSystem.init() change
> (jena-arq builds fine on 3.0.0 tag)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to