diff --git a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/targets/TargetChainRetriever.java b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/targets/TargetChainRetriever.java index d5ccfcf2d1..76d7231820 100644 --- a/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/targets/TargetChainRetriever.java +++ b/core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ast/targets/TargetChainRetriever.java @@ -86,7 +86,7 @@ public class TargetChainRetriever implements PlanNode { private final EffectiveTarget.EffectiveTargetFragment rsxTarget; private final List originalStatementMatchers; - private StackTraceElement[] stackTrace; + private final StackTraceElement[] stackTrace; private ValidationExecutionLogger validationExecutionLogger; public TargetChainRetriever(ConnectionsGroup connectionsGroup, @@ -330,50 +330,20 @@ private List readStatementsInBulk(Set variableNames) { Stream rootStatements = Stream .of(new EffectiveTarget.StatementsAndMatcher(List.of(next), currentStatementMatcher)); if (removedStatement && removedStatementTarget != null) { - Stream root = null; - Throwable t1 = null; - int failed = 0; - try { - root = removedStatementTarget.getRoot( + + if (!statementMatchers.contains(currentStatementMatcher)) { + // we only need to find the root if the currentStatementMatcher doesn't match anything in + // the query + Stream root = removedStatementTarget.getRoot( connectionsGroup, dataGraph, currentStatementMatcher, next); - } catch (Throwable e) { - failed++; - t1 = e; - } - if (failed == 1) { - logger.warn("currentStatementMatcher: " + currentStatementMatcher.toString()); - logger.warn("sparqlValuesDecl: " + sparqlValuesDecl); - logger.warn("queryFragment: " + queryFragment); - List collect = rootStatements - .collect(Collectors.toList()); - for (EffectiveTarget.StatementsAndMatcher statementsAndMatcher : collect) { - logger.warn(statementsAndMatcher.toString()); - } - for (StatementMatcher statementMatcher : statementMatchers) { - logger.warn("statementMatchers: " + statementMatcher.toString()); - } - for (StatementMatcher statementMatcher : removedStatementMatchers) { - logger.warn("removedStatementMatchers: " + statementMatcher.toString()); - } - for (StatementMatcher statementMatcher : originalStatementMatchers) { - logger.warn("originalStatementMatchers: " + statementMatcher.toString()); + if (root != null) { + rootStatements = root; } - - System.err.println("\n"); - t1.printStackTrace(); - System.err.println("\n"); - - rootStatements = collect.stream(); - System.out.println(); - throw new IllegalStateException("Failed to get root for removed statement!", t1); } - if (root != null) { - rootStatements = root; - } } List collect = rootStatements.collect(Collectors.toList());