You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@jena.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2022/03/25 13:39:00 UTC
[jira] [Commented] (JENA-2310) NPE with geospatial property function due to query rewrite index issue
[ https://issues.apache.org/jira/browse/JENA-2310?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17512385#comment-17512385 ]
ASF subversion and git services commented on JENA-2310:
-------------------------------------------------------
Commit cee0604d63fb50e6c0a7c32fc7b6397677e30400 in jena's branch refs/heads/main from Andy Seaborne
[ https://gitbox.apache.org/repos/asf?p=jena.git;h=cee0604 ]
Merge pull request #1234 from galbiston/expiring_index_race_condition_fix
[JENA-2310] NPE with geospatial property function due to query rewrite index issue
> NPE with geospatial property function due to query rewrite index issue
> ----------------------------------------------------------------------
>
> Key: JENA-2310
> URL: https://issues.apache.org/jira/browse/JENA-2310
> Project: Apache Jena
> Issue Type: Bug
> Components: GeoSPARQL
> Affects Versions: Jena 4.4.0
> Reporter: Lorenz Bühmann
> Assignee: Greg Albiston
> Priority: Major
>
> Using a GeoSPARQL query with a geospatial property function, e.g.
> {code:java}
> SELECT * {
> :x geo:hasGeometry ?geo1 .
> ?s2 geo:hasGeometry ?geo2 .
> ?geo1 geo:sfContains ?geo2
> }{code}
> leads to an nondeterministic NPE when we're doing this query a a larger dataset.
> The reason is explained here:
> - evaluation of the property function leads to {{GenericPropertyFunction}} class with
> {code:java}
> private QueryIterator bothBound(Binding binding, Node subject, Node predicate, Node object, ExecutionContext execCxt) {
> Graph graph = execCxt.getActiveGraph();
> QueryRewriteIndex queryRewriteIndex = QueryRewriteIndex.retrieve(execCxt);
> Boolean isPositiveResult = queryRewrite(graph, subject, predicate, object, queryRewriteIndex);
> if (isPositiveResult) {
> {code}
>
> which leads to the query rewrite part and in {{QueryRewriteIndex}} class we have
> {code:java}
> if (index.containsKey(key)) {
> result = index.get(key);
> } else {
> result = propertyFunction.testFilterFunction(subjectGeometryLiteral, objectGeometryLiteral);
> index.put(key, result);
> }
> {code}
> {{index}} is an {{ExpiringMap}} which extends {{ConcurrentHashMap}} with an additional {{TimerTask}} clearing the map periodically - and this is why we get an NPE sometimes. Have a look at the lines above, in particular
> {code:java}
> if (index.containsKey(key)){
> result = index.get(key);
> }
> {code}
> that part isn't atomic, thus, while {{containsKey}} could be true, the {{TimerTask}} might clear the map before we go to get - this will lead to a {{null}} value returned which will lead to an NPE in the check
> Since Java 8 the atomic way is to use {{computeIfAbsent}}, i.e. we can do
> {code:java}
> Boolean result = index.computeIfAbsent(key, k -> propertyFunction.testFilterFunction(subjectGeometryLiteral, objectGeometryLiteral));{code}
>
--
This message was sent by Atlassian Jira
(v8.20.1#820001)
---------------------------------------------------------------------
To unsubscribe, e-mail: jira-unsubscribe@jena.apache.org
For additional commands, e-mail: jira-help@jena.apache.org