From 916accbd0011f83cce86c4f850fd2e40796f666a Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Thu, 4 Jan 2024 18:32:21 +0100 Subject: [PATCH] beware the modifiable reference --- .../java/com/clevercloud/biscuit/datalog/Combinator.java | 5 ++--- src/main/java/com/clevercloud/biscuit/datalog/Origin.java | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/clevercloud/biscuit/datalog/Combinator.java b/src/main/java/com/clevercloud/biscuit/datalog/Combinator.java index bcde41cf..e32026c3 100644 --- a/src/main/java/com/clevercloud/biscuit/datalog/Combinator.java +++ b/src/main/java/com/clevercloud/biscuit/datalog/Combinator.java @@ -70,7 +70,7 @@ public Option>> getNext() { // we iterate over the facts that match the current predicate if (this.currentFacts.hasNext()) { final Tuple2 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 @@ -129,8 +129,7 @@ public Option>> getNext() { if (opt.isDefined()) { Tuple2> 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; diff --git a/src/main/java/com/clevercloud/biscuit/datalog/Origin.java b/src/main/java/com/clevercloud/biscuit/datalog/Origin.java index d18df2d7..8f1b86e9 100644 --- a/src/main/java/com/clevercloud/biscuit/datalog/Origin.java +++ b/src/main/java/com/clevercloud/biscuit/datalog/Origin.java @@ -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() {