shawnsmith opened a new issue, #3622:
URL: https://github.com/apache/jena/issues/3622
### Version
5.6.0
### What happened?
Simple code to reproduce the NullPointerException:
```java
class DescribeTest {
@Test
void testDescribeSubstitution() {
QueryExec.graph(Graph.emptyGraph)
.query("DESCRIBE ?item")
.substitution("item",
NodeFactory.createURI("https://example.com/item"))
.build();
}
}
```
The problem is that `Query.getQueryPattern() == null` which isn't expected
by `QuerySyntaxSubstituteScope.scopeCheck()`.
There's a simple workaround:
```
# This query throws NPE
DESCRIBE ?item
# This query works
DESCRIBE ?item WHERE {}
# This approach also works
ParameterizedSparqlString sparql = new ParameterizedSparqlString("DESCRIBE
?item");
sparql.setParam("item", NodeFactory.createURI("https://example.com/item"));
Query query = sparql.asQuery();
...
```
### Relevant output and stacktrace
```shell
java.lang.NullPointerException: Cannot invoke
"org.apache.jena.sparql.syntax.Element.visit(org.apache.jena.sparql.syntax.ElementVisitor)"
because "el" is null
at
org.apache.jena.sparql.syntax.ElementWalker.walk(ElementWalker.java:37)
at
org.apache.jena.sparql.syntax.ElementWalker.walk(ElementWalker.java:32)
at
org.apache.jena.sparql.syntax.syntaxtransform.QuerySyntaxSubstituteScope.checkPattern(QuerySyntaxSubstituteScope.java:44)
at
org.apache.jena.sparql.syntax.syntaxtransform.QuerySyntaxSubstituteScope.scopeCheck(QuerySyntaxSubstituteScope.java:39)
at
org.apache.jena.sparql.syntax.syntaxtransform.QueryTransformOps.transformSubstitute(QueryTransformOps.java:113)
at
org.apache.jena.sparql.syntax.syntaxtransform.QueryTransformOps.replaceVars(QueryTransformOps.java:86)
at
org.apache.jena.sparql.exec.QueryExecDatasetBuilder.build(QueryExecDatasetBuilder.java:207)
at
org.apache.jena.arq.junit.sparql.tests.DescribeTest.testDescribeSubstitution(DescribeTest.java:16)
```
### Are you interested in making a pull request?
None
--
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]