Ostrzyciel opened a new issue, #2578:
URL: https://github.com/apache/jena/issues/2578

   ### Version
   
   5.0.0
   
   ### What happened?
   
   To be honest, I don't know if this is a bug or I'm just horribly confused. I 
wrote a deserializer for Jena that outputs quads with "null" in the graph term 
position when it's a default graph. When I then tried to serialize such a 
dataset using RIOT's serializers, I've noticed that for JSON-LD 1.1 the 
serialization fails completely, while for others it works.
   
   I dug deeper and found out that Jena has 3 ways to represent the default 
graph: `null`, `Quad.defaultGraphIRI`, and `Quad.defaultGraphNodeGenerated`. I 
read the javadoc of the latter two and honestly, I still don't fully understand 
what's the difference. I then checked how these different implementations 
handle the different flavors of default graphs.
   
   The code is here (Apache 2.0): 
https://github.com/Ostrzyciel/jena-default-graphs/blob/main/jena-default-graphs/src/main/java/org/example/Main.java
   
   Output is attached below.
   
   N-Quads, RDF-PROTO, RDF-THRIFT serialize/deserialize the default graph 
correctly in all three variants. JSON-LD 1.1 fails with a null pointer 
exception for the null variant (easy fix). TriG fails silently and just outputs 
nothing for the null variant (also likely to be an easy fix).
   
   All parsers output `Quad.defaultGraphIRI` which I guess makes it the "right" 
choice when implementing parsers.
   
   What I don't know is if this is a bug at all or I'm just being confused. If 
this is a bug, I can happily fix the null handling in TriG and JSON-LD.
   
   ### Relevant output and stacktrace
   
   ```shell
   Empty output for null graph in TriG/pretty
   Failed to write null graph in JSON-LD-11/pretty
   org.apache.jena.shared.JenaException: Exception while writing JSON-LD 1.1
        at 
org.apache.jena.riot.writer.JsonLD11Writer.write$(JsonLD11Writer.java:123)
        at 
org.apache.jena.riot.writer.JsonLD11Writer.write(JsonLD11Writer.java:73)
        at org.apache.jena.riot.RDFWriter.write$(RDFWriter.java:261)
        at org.apache.jena.riot.RDFWriter.output(RDFWriter.java:219)
        at org.apache.jena.riot.RDFWriter.output(RDFWriter.java:158)
        at 
org.apache.jena.riot.RDFWriterBuilder.output(RDFWriterBuilder.java:207)
        at org.apache.jena.riot.RDFDataMgr.write$(RDFDataMgr.java:809)
        at org.apache.jena.riot.RDFDataMgr.write(RDFDataMgr.java:754)
        at org.example.Main.main(Main.java:63)
   Caused by: java.lang.NullPointerException: Cannot invoke 
"org.apache.jena.graph.Node.isBlank()" because "node" is null
        at 
org.apache.jena.riot.system.JenaTitanium.resource(JenaTitanium.java:133)
        at 
org.apache.jena.riot.system.JenaTitanium.lambda$convert$0(JenaTitanium.java:60)
        at 
org.apache.jena.atlas.iterator.Iter$IterMap.lambda$forEachRemaining$0(Iter.java:432)
        at 
org.apache.jena.mem2.store.fast.FastArrayBunch$1.forEachRemaining(FastArrayBunch.java:164)
        at 
org.apache.jena.mem2.iterator.IteratorOfJenaSets.forEachRemaining(IteratorOfJenaSets.java:71)
        at 
org.apache.jena.atlas.iterator.Iter$IterMap.forEachRemaining(Iter.java:432)
        at org.apache.jena.atlas.iterator.Iter.forEachRemaining(Iter.java:927)
        at 
org.apache.jena.atlas.iterator.IteratorConcat.forEachRemaining(IteratorConcat.java:99)
        at 
org.apache.jena.riot.system.JenaTitanium.convert(JenaTitanium.java:49)
        at 
org.apache.jena.riot.writer.JsonLD11Writer.write$(JsonLD11Writer.java:91)
        ... 8 more
   
   To serialize                       Format                   
Status/deserialized
   null graph                         TriG/pretty              empty output   
   null graph                         JSON-LD-11/pretty        serialization 
failed
   null graph                         N-Quads/utf-8            
Quad.defaultGraphIRI
   null graph                         RDF-PROTO                
Quad.defaultGraphIRI
   null graph                         RDF-THRIFT               
Quad.defaultGraphIRI
   Quad.defaultGraphNodeGenerated     TriG/pretty              
Quad.defaultGraphIRI
   Quad.defaultGraphNodeGenerated     JSON-LD-11/pretty        
Quad.defaultGraphIRI
   Quad.defaultGraphNodeGenerated     N-Quads/utf-8            
Quad.defaultGraphIRI
   Quad.defaultGraphNodeGenerated     RDF-PROTO                
Quad.defaultGraphIRI
   Quad.defaultGraphNodeGenerated     RDF-THRIFT               
Quad.defaultGraphIRI
   Quad.defaultGraphIRI               TriG/pretty              
Quad.defaultGraphIRI
   Quad.defaultGraphIRI               JSON-LD-11/pretty        
Quad.defaultGraphIRI
   Quad.defaultGraphIRI               N-Quads/utf-8            
Quad.defaultGraphIRI
   Quad.defaultGraphIRI               RDF-PROTO                
Quad.defaultGraphIRI
   Quad.defaultGraphIRI               RDF-THRIFT               
Quad.defaultGraphIRI
   ```
   
   
   ### Are you interested in making a pull request?
   
   Yes


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to