From 3b5791dea8656bfc6a98fb3fd7ef6db4a2f4deec Mon Sep 17 00:00:00 2001 From: John Bogovic <bogovicj@janelia.hhmi.org> Date: Tue, 17 Oct 2023 14:35:32 -0400 Subject: [PATCH] fix: don't add a node path to itself * avoid stack overflow * and be quiet --- .../saalfeldlab/n5/ui/DatasetSelectorDialog.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/janelia/saalfeldlab/n5/ui/DatasetSelectorDialog.java b/src/main/java/org/janelia/saalfeldlab/n5/ui/DatasetSelectorDialog.java index 7f01200d..7c6da05a 100644 --- a/src/main/java/org/janelia/saalfeldlab/n5/ui/DatasetSelectorDialog.java +++ b/src/main/java/org/janelia/saalfeldlab/n5/ui/DatasetSelectorDialog.java @@ -615,7 +615,6 @@ private void openContainer(final Function<String, N5Reader> n5Fun, final Supplie n5 = n5Fun.apply(n5Path); final String rootPath = pathToRoot.apply(n5Path); - System.out.println("rootPath: " + rootPath); if (n5 == null) { messageLabel.setVisible(false); @@ -623,7 +622,6 @@ private void openContainer(final Function<String, N5Reader> n5Fun, final Supplie return; } - // copy list final ArrayList<N5MetadataParser<?>> parserList = new ArrayList<>(); @@ -680,10 +678,14 @@ private void openContainer(final Function<String, N5Reader> n5Fun, final Supplie final Consumer<N5TreeNode> callback = (x) -> { SwingUtilities.invokeLater(() -> { if (x.getMetadata() != null) { - // get the node at the requested path, or add it if not - // present + // get the node at the requested path, or add it if not present final N5SwingTreeNode node = (N5SwingTreeNode)rootNode.getDescendants(y -> pathsEqual(y.getPath(), x.getPath())).findFirst() - .orElse(rootNode.addPath(x.getPath())); + .orElseGet( () -> { + if (rootNode.getPath().equals(x.getPath())) + return null; + else + return rootNode.addPath(x.getPath()); + }); // update the node's metadata if (node != null) {