Skip to content

Commit

Permalink
beware the modifiable reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Jan 4, 2024
1 parent a28355d commit 916accb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/main/java/com/clevercloud/biscuit/datalog/Combinator.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {
// we iterate over the facts that match the current predicate
if (this.currentFacts.hasNext()) {
final Tuple2<Origin, Fact> t = this.currentFacts.next();
Origin currentOrigin = t._1;
Origin currentOrigin = t._1.clone();
Fact fact = t._2;

// create a new MatchedVariables in which we fix variables we could unify from our first predicate and the current fact
Expand Down Expand Up @@ -129,8 +129,7 @@ public Option<Tuple2<Origin, Map<Long, Term>>> getNext() {

if (opt.isDefined()) {
Tuple2<Origin, Map<Long, Term>> t = opt.get();
t._1.union(currentOrigin);
return Option.some(t);
return Option.some(new Tuple2<>(t._1.union(currentOrigin), t._2));
} else {
currentOrigin = null;
currentIt = null;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/clevercloud/biscuit/datalog/Origin.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public void add(long i) {
inner.add(i);
}

public void union(Origin other) {
this.inner.addAll(other.inner);
public Origin union(Origin other) {
Origin o = this.clone();
o.inner.addAll(other.inner);
return o;
}

public Origin clone() {
Expand Down

0 comments on commit 916accb

Please sign in to comment.