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

SPARQL replace causes query to crash when non-existent group in replacement pattern

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Jena 2.11.0
    • Jena 2.12.0
    • ARQ

    Description

      If a replacement string uses a group that's not in the pattern, the whole query crashes (as opposed to the value of replace just being an error value). Version, query, and command line to reproduce:

      $ sparql --version && cat query.rq && sparql --query query.rq --data data.n3 
      Jena:       VERSION: 2.11.0
      Jena:       BUILD_DATE: 2013-09-12T10:49:49+0100
      ARQ:        VERSION: 2.11.0
      ARQ:        BUILD_DATE: 2013-09-12T10:49:49+0100
      RIOT:       VERSION: 2.11.0
      RIOT:       BUILD_DATE: 2013-09-12T10:49:49+0100
      select (replace("x", ".", "$1") as ?error) where {}
      Exception
      java.lang.IndexOutOfBoundsException: No group 1
              at java.util.regex.Matcher.start(Matcher.java:375)
              at java.util.regex.Matcher.appendReplacement(Matcher.java:880)
              at java.util.regex.Matcher.replaceAll(Matcher.java:955)
              at com.hp.hpl.jena.sparql.expr.nodevalue.XSDFuncOp.strReplace(XSDFuncOp.java:421)
              at com.hp.hpl.jena.sparql.expr.E_StrReplace.eval(E_StrReplace.java:52)
              at com.hp.hpl.jena.sparql.expr.ExprFunctionN.eval(ExprFunctionN.java:115)
              at com.hp.hpl.jena.sparql.expr.ExprFunctionN.eval(ExprFunctionN.java:112)
              at com.hp.hpl.jena.sparql.core.VarExprList.get(VarExprList.java:82)
              at com.hp.hpl.jena.sparql.engine.iterator.QueryIterAssign.accept(QueryIterAssign.java:68)
              at com.hp.hpl.jena.sparql.engine.iterator.QueryIterProcessBinding.hasNextBinding(QueryIterProcessBinding.java:64)
              at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
              at com.hp.hpl.jena.sparql.engine.iterator.QueryIterConvert.hasNextBinding(QueryIterConvert.java:59)
              at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
              at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:40)
              at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
              at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorWrapper.hasNextBinding(QueryIteratorWrapper.java:40)
              at com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:112)
              at com.hp.hpl.jena.sparql.engine.ResultSetStream.hasNext(ResultSetStream.java:75)
              at com.hp.hpl.jena.sparql.resultset.ResultSetMem.<init>(ResultSetMem.java:97)
              at com.hp.hpl.jena.query.ResultSetFactory.makeRewindable(ResultSetFactory.java:420)
              at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:149)
              at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:132)
              at com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:120)
              at com.hp.hpl.jena.sparql.resultset.TextOutput.format(TextOutput.java:67)
              at com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:135)
              at com.hp.hpl.jena.sparql.util.QueryExecUtils.outputResultSet(QueryExecUtils.java:157)
              at com.hp.hpl.jena.sparql.util.QueryExecUtils.doSelectQuery(QueryExecUtils.java:199)
              at com.hp.hpl.jena.sparql.util.QueryExecUtils.executeQuery(QueryExecUtils.java:75)
              at arq.query.queryExec(query.java:194)
              at arq.query.exec(query.java:145)
              at arq.cmdline.CmdMain.mainMethod(CmdMain.java:101)
              at arq.cmdline.CmdMain.mainRun(CmdMain.java:63)
              at arq.cmdline.CmdMain.mainRun(CmdMain.java:50)
              at arq.query.main(query.java:63)
              at arq.sparql.main(sparql.java:27)
      

      I would have expected

      ---------
      | error |
      =========
      |       |
      ---------
      

      Attachments

        Activity

          People

            andy Andy Seaborne
            taylorj Joshua Taylor
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: