Skip to content

Commit 944eb81

Browse files
committed
Fix race condition in static class initialization
1 parent 57ef51d commit 944eb81

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/vocabulary/RdfNamespace.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ static Map<String, String> createPrefixMap( final KnownVersion metaModelVersion
5757
result.put( samme.getShortForm(), samme.getNamespace() );
5858
final UNIT unit = new UNIT( metaModelVersion, samm );
5959
result.put( unit.getShortForm(), unit.getNamespace() );
60-
result.put( SammNs.RDF.getShortForm(), SammNs.RDF.getNamespace() );
61-
result.put( SammNs.RDFS.getShortForm(), SammNs.RDFS.getNamespace() );
62-
result.put( SammNs.XSD.getShortForm(), SammNs.XSD.getNamespace() );
60+
result.put( SammNs.RDF().getShortForm(), SammNs.RDF().getNamespace() );
61+
result.put( SammNs.RDFS().getShortForm(), SammNs.RDFS().getNamespace() );
62+
result.put( SammNs.XSD().getShortForm(), SammNs.XSD().getNamespace() );
6363
return result;
6464
}
6565

@@ -69,9 +69,9 @@ static Map<String, String> createPrefixMap() {
6969
result.put( SammNs.SAMMC.getShortForm(), SammNs.SAMMC.getNamespace() );
7070
result.put( SammNs.SAMME.getShortForm(), SammNs.SAMME.getNamespace() );
7171
result.put( SammNs.UNIT.getShortForm(), SammNs.UNIT.getNamespace() );
72-
result.put( SammNs.RDF.getShortForm(), SammNs.RDF.getNamespace() );
73-
result.put( SammNs.RDFS.getShortForm(), SammNs.RDFS.getNamespace() );
74-
result.put( SammNs.XSD.getShortForm(), SammNs.XSD.getNamespace() );
72+
result.put( SammNs.RDF().getShortForm(), SammNs.RDF().getNamespace() );
73+
result.put( SammNs.RDFS().getShortForm(), SammNs.RDFS().getNamespace() );
74+
result.put( SammNs.XSD().getShortForm(), SammNs.XSD().getNamespace() );
7575
return result;
7676
}
7777
}

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/vocabulary/SammNs.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020
/**
2121
* RDF vocabularies of the SAMM meta model namespaces
2222
*/
23+
@SuppressWarnings( { "checkstyle:AbbreviationAsWordInName", "checkstyle:MethodName" } ) // RDF vocabularies are exempt from naming rules
2324
public class SammNs {
2425
public static final SAMM SAMM = new SAMM( KnownVersion.getLatest() );
2526
public static final SAMMC SAMMC = new SAMMC( KnownVersion.getLatest() );
2627
public static final SAMME SAMME = new SAMME( KnownVersion.getLatest(), SAMM );
2728
public static final UNIT UNIT = new UNIT( KnownVersion.getLatest(), SAMM );
28-
public static final RdfNamespace RDF = new SimpleRdfNamespace( "rdf", org.apache.jena.vocabulary.RDF.getURI() );
29-
public static final RdfNamespace RDFS = new SimpleRdfNamespace( "rdfs", org.apache.jena.vocabulary.RDFS.getURI() );
30-
public static final RdfNamespace XSD = new SimpleRdfNamespace( "xsd", org.apache.jena.vocabulary.XSD.getURI() );
29+
30+
private static RdfNamespace RDF;
31+
private static RdfNamespace RDFS;
32+
private static RdfNamespace XSD;
3133

3234
private SammNs() {
3335
}
@@ -41,12 +43,33 @@ public static Stream<RdfNamespace> sammNamespaces() {
4143
return Stream.of( SAMM, SAMMC, SAMME, UNIT );
4244
}
4345

46+
public static synchronized RdfNamespace RDF() {
47+
if ( RDF == null ) {
48+
RDF = new SimpleRdfNamespace( "rdf", org.apache.jena.vocabulary.RDF.getURI() );
49+
}
50+
return RDF;
51+
}
52+
53+
public static synchronized RdfNamespace RDFS() {
54+
if ( RDFS == null ) {
55+
RDFS = new SimpleRdfNamespace( "rdfs", org.apache.jena.vocabulary.RDFS.getURI() );
56+
}
57+
return RDFS;
58+
}
59+
60+
public static synchronized RdfNamespace XSD() {
61+
if ( XSD == null ) {
62+
XSD = new SimpleRdfNamespace( "xsd", org.apache.jena.vocabulary.XSD.getURI() );
63+
}
64+
return XSD;
65+
}
66+
4467
/**
4568
* All "well-known" RDF namespaces
4669
*
4770
* @return the namespaces
4871
*/
4972
public static Stream<RdfNamespace> wellKnownNamespaces() {
50-
return Stream.concat( sammNamespaces(), Stream.of( RDF, RDFS, XSD ) );
73+
return Stream.concat( sammNamespaces(), Stream.of( RDF(), RDFS(), XSD() ) );
5174
}
5275
}

0 commit comments

Comments
 (0)