Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
Jena 3.16.0
-
Oracle jdk-14.0.1
Description
The following query can be parsed, but cannot be serialized back:
import org.apache.jena.query.Query; import org.apache.jena.query.QueryFactory; public class MinimalTest { public static void main(String[] args) { String queryString = "SELECT ?a WHERE { <%s> <http://ex.com> <http://ex.com> }"; Query q = QueryFactory.create(queryString); String serialized = q.serialize(); System.out.println(serialized); } }
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: begin 0, end 51, length 50 at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3756) at java.base/java.lang.String.substring(String.java:1902) at org.apache.jena.shared.impl.PrefixMappingImpl.qnameFor(PrefixMappingImpl.java:235) at org.apache.jena.sparql.util.FmtUtils.prefixFor(FmtUtils.java:494) at org.apache.jena.sparql.util.FmtUtils.stringForURI(FmtUtils.java:448) at org.apache.jena.sparql.util.FmtUtils.stringForURI(FmtUtils.java:431) at org.apache.jena.sparql.util.FmtUtils.stringForNode(FmtUtils.java:374) at org.apache.jena.sparql.util.FmtUtils.stringForNode(FmtUtils.java:348) at org.apache.jena.sparql.serializer.FormatterBase.slotToString(FormatterBase.java:57) at org.apache.jena.sparql.serializer.FormatterElement.setWidths(FormatterElement.java:615) at org.apache.jena.sparql.serializer.FormatterElement.formatTriples(FormatterElement.java:503) at org.apache.jena.sparql.serializer.FormatterElement.flush(FormatterElement.java:558) at org.apache.jena.sparql.serializer.FormatterElement.visit(FormatterElement.java:165) at org.apache.jena.sparql.syntax.ElementPathBlock.visit(ElementPathBlock.java:94) at org.apache.jena.sparql.serializer.FormatterElement.visit(FormatterElement.java:321) at org.apache.jena.sparql.syntax.ElementGroup.visit(ElementGroup.java:120) at org.apache.jena.sparql.serializer.FormatterElement.visitAsGroup(FormatterElement.java:453) at org.apache.jena.sparql.serializer.QuerySerializer.visitQueryPattern(QuerySerializer.java:207) at org.apache.jena.query.Query.visit(Query.java:770) at org.apache.jena.query.Query.serialize(Query.java:928) at org.apache.jena.query.Query.serialize(Query.java:905) at org.apache.jena.query.Query.serialize(Query.java:895) at org.apache.jena.query.Query.serialize(Query.java:856) at MinimalTest.main(MinimalTest.java:10)
I am not entirely sure whether it is
- The query which is invalid, in which case there is a bug in the parser
- The serialization which should not fail, in which case the serializer has a bug.