NumberFormatException when casting to xsd:int in ARQ, with possible infinite
loop
---------------------------------------------------------------------------------
Key: JENA-231
URL: https://issues.apache.org/jira/browse/JENA-231
Project: Apache Jena
Issue Type: Bug
Components: ARQ
Affects Versions: ARQ 2.9.0
Reporter: Richard Cyganiak
I'm running the following query on an empty dataset using the sparql command
line command:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT (xsd:int(" 1") AS ?x) {}
The result is an error:
java.lang.NumberFormatException: For input string: " 1"
I know that this is not a valid lexical form for xsd:int. But I expected this
to produce an empty result set, like other non-int strings such as
xsd:int("NaN"), and not an exception.
The problem appears to be triggered by the presence of leading or trailing
spaces around an otherwise correct number. The same problem is present when
casting to other types such as xsd:decimal. The problem is *not* present for
xsd:double.
Command and full stack trace follows.
(I have a user report of an infinite loop in ARQ code that I distilled down to
this root issue. The report involved a cast to xsd:decimal in a FILTER
expression. The dataset is a D2RQ dataset, and the values came from a CHAR
column, hence the extra spaces. I have not succeeded in actually reproducing
the infinite loop as I don't have access to the original database.)
cygris:~$ sparql --query rob.sparql --data empty.nt
Exception
java.lang.NumberFormatException: For input string: " 1"
at
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:449)
at java.math.BigInteger.<init>(BigInteger.java:316)
at java.math.BigInteger.<init>(BigInteger.java:451)
at com.hp.hpl.jena.sparql.expr.NodeValue._setByValue(NodeValue.java:957)
at
com.hp.hpl.jena.sparql.expr.NodeValue.nodeToNodeValue(NodeValue.java:915)
at com.hp.hpl.jena.sparql.expr.NodeValue.makeNode(NodeValue.java:231)
at com.hp.hpl.jena.sparql.expr.NodeValue.makeNode(NodeValue.java:238)
at
com.hp.hpl.jena.sparql.function.CastXSD$Instance.cast(CastXSD.java:96)
at
com.hp.hpl.jena.sparql.function.CastXSD_Numeric$Instance.cast(CastXSD_Numeric.java:61)
at
com.hp.hpl.jena.sparql.function.CastXSD$Instance.exec(CastXSD.java:86)
at
com.hp.hpl.jena.sparql.function.FunctionBase1.exec(FunctionBase1.java:53)
at
com.hp.hpl.jena.sparql.function.FunctionBase.exec(FunctionBase.java:68)
at
com.hp.hpl.jena.sparql.expr.E_Function.evalSpecial(E_Function.java:71)
at
com.hp.hpl.jena.sparql.expr.ExprFunctionN.eval(ExprFunctionN.java:102)
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:108)
at
com.hp.hpl.jena.sparql.engine.iterator.QueryIterConvert.hasNextBinding(QueryIterConvert.java:65)
at
com.hp.hpl.jena.sparql.engine.iterator.QueryIteratorBase.hasNext(QueryIteratorBase.java:108)
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:108)
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:108)
at
com.hp.hpl.jena.sparql.engine.ResultSetStream.hasNext(ResultSetStream.java:72)
at
com.hp.hpl.jena.sparql.resultset.ResultSetMem.<init>(ResultSetMem.java:95)
at
com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:147)
at
com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:130)
at
com.hp.hpl.jena.sparql.resultset.TextOutput.write(TextOutput.java:118)
at
com.hp.hpl.jena.sparql.resultset.TextOutput.format(TextOutput.java:65)
at
com.hp.hpl.jena.query.ResultSetFormatter.out(ResultSetFormatter.java:134)
at
com.hp.hpl.jena.sparql.util.QueryExecUtils.outputResultSet(QueryExecUtils.java:169)
at
com.hp.hpl.jena.sparql.util.QueryExecUtils.doSelectQuery(QueryExecUtils.java:211)
at
com.hp.hpl.jena.sparql.util.QueryExecUtils.executeQuery(QueryExecUtils.java:75)
at arq.query.queryExec(query.java:186)
at arq.query.exec(query.java:145)
at arq.cmdline.CmdMain.mainMethod(CmdMain.java:97)
at arq.cmdline.CmdMain.mainRun(CmdMain.java:59)
at arq.cmdline.CmdMain.mainRun(CmdMain.java:46)
at arq.query.main(query.java:65)
at arq.sparql.main(sparql.java:27)
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira