Skip to content

Commit 96bc395

Browse files
committed
fix: VariationTree not always validating the root
The assertion that the given root node in the constructors of VariationTree was not always checked, in particular not for the default constructor by the record.
1 parent adf19ff commit 96bc395

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/main/java/org/variantsync/diffdetective/variation/diff/construction/GumTreeDiff.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static <L extends Label> VariationDiff<L> diffUsingMatching(VariationTree
4848
matcher
4949
);
5050

51-
return new VariationDiff<>(root, new CompositeSource("diffUsingMatching", before.source(), after.source()));
51+
return new VariationDiff<>(root, new CompositeSource("diffUsingMatching", before, after));
5252
}
5353

5454
/**

src/main/java/org/variantsync/diffdetective/variation/tree/VariationTree.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,16 @@
3434
/**
3535
* Representation of a concrete variation tree with source information.
3636
*
37-
* @param root the root of the variation tree
38-
* @param source from which source code the variation tree was obtained
3937
* @param <L> The type of label stored in this tree.
4038
*
4139
* @see VariationTreeNode
4240
* @author Benjamin Moosherr
4341
*/
44-
public record VariationTree<L extends Label>(
45-
VariationTreeNode<L> root,
46-
Source source
47-
) implements Source {
48-
/** Creates a {@code VariationTree} with the given root and an unknown source. */
42+
public class VariationTree<L extends Label> implements Source {
43+
private final VariationTreeNode<L> root;
44+
private final Source source;
45+
46+
/** Creates a {@code VariationTree} with the given root and an {@link Source::Unknown unknown} source. */
4947
public VariationTree(VariationTreeNode<L> root) {
5048
this(root, Source.Unknown);
5149
}
@@ -143,7 +141,7 @@ public static <T extends VariationNode<T, L>, L extends Label> VariationTree<L>
143141
public VariationDiff<L> toVariationDiff(final Function<VariationTreeNode<L>, DiffNode<L>> nodeConverter) {
144142
return new VariationDiff<>(
145143
DiffNode.unchanged(nodeConverter, root()),
146-
new CompositeSource("VariationTree.toVariationDiff", source())
144+
new CompositeSource("VariationTree.toVariationDiff", source)
147145
);
148146
}
149147

@@ -235,8 +233,16 @@ public void assertConsistency() {
235233
forAllPreorder(VariationTreeNode::assertConsistency);
236234
}
237235

236+
public VariationTreeNode<L> root() {
237+
return root;
238+
}
239+
240+
/**
241+
* Returns the source of this VariationTree (i.e., the data this VariationTree was created from).
242+
* @see Source
243+
*/
238244
public Source getSource() {
239-
return source();
245+
return source;
240246
}
241247

242248
@Override

0 commit comments

Comments
 (0)