Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
598 changes: 427 additions & 171 deletions AGENTS.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ public Function<ArrayBindingSet, Binding> getDirectGetBinding(String bindingName
}
return a -> {
Value value = a.values[index];
if (value == NULL_VALUE) {
value = null;
}
if (value != null) {
if (value != null && value != NULL_VALUE) {
return new SimpleBinding(bindingName, value);
} else {
return null;
Expand Down Expand Up @@ -416,7 +413,7 @@ public ArrayBindingSetIterator() {
@Override
public boolean hasNext() {
while (index < values.length) {
if (values[index] != null) {
if (values[index] != null && values[index] != NULL_VALUE) {
return true;
}
index++;
Expand All @@ -426,20 +423,10 @@ public boolean hasNext() {

@Override
public Binding next() {
while (index < values.length) {
if (values[index] != null) {
String name = bindingNames[index];
Value value = values[index++];
if (value == NULL_VALUE) {
value = null;
}
if (value != null) {
return new SimpleBinding(name, value);
} else {
return null;
}
}
index++;
if (hasNext()) {
String name = bindingNames[index];
Value value = values[index++];
return new SimpleBinding(name, value);
}

throw new NoSuchElementException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ private ProjectionFinder() {
@Override
public void meet(Projection node) throws RuntimeException {
super.meet(node);

VariableFinder findVariables = new VariableFinder();
node.visit(findVariables);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* ******************************************************************************
* Copyright (c) 2025 Eclipse RDF4J contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
* ******************************************************************************
*/
package org.eclipse.rdf4j.query.algebra.evaluation;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.LinkedHashSet;
import java.util.Set;

import org.eclipse.rdf4j.model.vocabulary.OWL;
import org.eclipse.rdf4j.query.Binding;
import org.junit.jupiter.api.Test;

/**
* Reproduces a NullPointerException when an ArrayBindingSet contains an explicit null (UNDEF) binding value and is
* copied into a QueryBindingSet. Prior to the fix, iterating the ArrayBindingSet could yield a null Binding, which
* caused NPE in QueryBindingSet.addBinding.
*/
public class ArrayBindingSetNullHandlingTest {

@Test
public void iteratorShouldNotReturnNullBindings() {
ArrayBindingSet bs = new ArrayBindingSet("myVar", "unbound", "mappingProp", "const");
// Explicitly set an UNDEF/null binding using the direct setter (stores a sentinel NULL_VALUE)
bs.getDirectSetBinding("myVar").accept(null, bs);
// Add a real binding so iteration has at least one valid element
bs.getDirectSetBinding("mappingProp").accept(OWL.EQUIVALENTCLASS, bs);

for (Binding b : bs) {
assertNotNull(b, "iterator must not yield null Binding elements");
}
}

@Test
public void copyingToQueryBindingSetMustSkipUndefBindings() {
ArrayBindingSet bs = new ArrayBindingSet("myVar", "unbound", "mappingProp", "const");
// myVar is explicitly present with UNDEF value
bs.getDirectSetBinding("myVar").accept(null, bs);
// mappingProp has a concrete value
bs.getDirectSetBinding("mappingProp").accept(OWL.EQUIVALENTCLASS, bs);

// Creating a QueryBindingSet from the ArrayBindingSet should not throw
QueryBindingSet qbs = assertDoesNotThrow(() -> new QueryBindingSet(bs));

assertTrue(qbs.hasBinding("mappingProp"));
assertEquals(OWL.EQUIVALENTCLASS, qbs.getValue("mappingProp"));
// UNDEF binding must not appear in the resulting set
assertFalse(qbs.hasBinding("myVar"));
assertEquals(1, qbs.size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ public static void process(ASTOperationContainer container) throws MalformedQuer
whereClause.jjtAccept(collector, null);

Set<ASTSelect> selectClauses = collector.getSelectClauses();
// process nested SELECT wildcards deepest-first so inner subqueries are expanded
// before their parents collect variables
java.util.List<ASTSelect> ordered = new java.util.ArrayList<>(selectClauses);
ordered.sort(java.util.Comparator.comparingInt(WildcardProjectionProcessor::depth).reversed());

for (ASTSelect selectClause : selectClauses) {
for (ASTSelect selectClause : ordered) {
if (selectClause.isWildcard()) {
ASTSelectQuery q = (ASTSelectQuery) selectClause.jjtGetParent();

Expand Down Expand Up @@ -95,6 +99,16 @@ public static void process(ASTOperationContainer container) throws MalformedQuer
}
}

private static int depth(Node n) {
int d = 0;
Node p = n.jjtGetParent();
while (p != null) {
d++;
p = p.jjtGetParent();
}
return d;
}

private static void addQueryVars(ASTWhereClause queryBody, Node wildcardNode) throws MalformedQueryException {
QueryVariableCollector visitor = new QueryVariableCollector();

Expand Down
Loading
Loading