TopQuadrant / shacl

SHACL API in Java based on Apache Jena
Apache License 2.0
217 stars 61 forks source link

Bug in ValidationEngine #127

Closed beaudet closed 2 years ago

beaudet commented 2 years ago

Greetings,

I'm slowly learning my way through SHACL and appreciate having the topbraid open source libraries available to execute constraints.

I recently ran into what I think is a bug at Line 389 of org.topbraid.shacl.validation.ValidationEngine

When I run the validation with the following compound path syntax:

sh:property [
    sh:path ( crm:P46_is_composed_of crm:P2_has_type ) ;
    sh:hasValue aat:300133026 ;
];

I'm getting a strange runtime exception that I can't break into with the debugger:

java.lang.NoSuchFieldError: emptyContext

Line 389 that results in the exception is:

Iterator<Node> it = PathEval.eval(focusNode.getModel().getGraph(), focusNode.asNode(), jenaPath, Context.emptyContext);

and, Context.emptyContext in fact no longer exists in Jena 4.3.1. It seems to have been change from a member to a method at some point.

I suspect the fix is to just update Context.emptyContext to Context.emptyContext()

Happy to provide more information and sorry I don't have a fully formed test case but this should be pretty straightforward to reproduce with any property constraint containing a path. Note that sh:path is not sufficient itself - there has to be an actual check like sh:hasValue in order to make it to line 389.

Thanks!

beaudet commented 2 years ago

A NoSuchFieldError is thrown if an application attempts to access a field of a class, and that class no longer has that field.

HolgerKnublauch commented 2 years ago

The SHACL API is currently implemented against Jena 4.2.0. I believe there are other changes in 4.3.0 that may cause SHACL not to work. We plan to upgrade to a newer Jena version very soon and hope to have an update for that, but I cannot give a timeline. Meanwhile, make sure your application's environment uses 4.2.

beaudet commented 2 years ago

Thanks, I updated the SHACL code for Jena 4.3.1 and will send a pull request tomorrow when I get a few minutes. All of the tests seem to pass but I'm not sure if there's 100% test coverage or not. There were some small issues with Jena 4.2 that forced me to go to 4.3.0-snapshot and now 4.3.1 since that appears to be the latest.

beaudet commented 2 years ago

Pull request was accepted and subsequent fixes applied at this point, so closing issue now.