Uploaded image for project: 'Apache Jena'
  1. Apache Jena
  2. JENA-1941

Parsed query cannot get serialized

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • Jena 3.16.0
    • Jena 3.17.0
    • ARQ, Jena
    • 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

      1. The query which is invalid, in which case there is a bug in the parser
      2. The serialization which should not fail, in which case the serializer has a bug.

      Attachments

        Activity

          People

            andy Andy Seaborne
            michaelcochez Michael Cochez
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 20m
                20m