From 20e6ba3f84d4073f17e2da5abd3e76b71f7adead Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 10 Jul 2018 22:19:51 +0100 Subject: [PATCH] KeyRemover.insertTree: rewrite without try/catch block --- src/main/java/net/kemitix/gitdb/impl/KeyRemover.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/kemitix/gitdb/impl/KeyRemover.java b/src/main/java/net/kemitix/gitdb/impl/KeyRemover.java index 392e540..847db08 100644 --- a/src/main/java/net/kemitix/gitdb/impl/KeyRemover.java +++ b/src/main/java/net/kemitix/gitdb/impl/KeyRemover.java @@ -26,7 +26,6 @@ import net.kemitix.mon.maybe.Maybe; import net.kemitix.mon.result.Result; import org.eclipse.jgit.lib.*; -import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; import java.util.function.Predicate; @@ -101,10 +100,8 @@ class KeyRemover { * @return the name of the tree object. */ private Result insertTree(final TreeFormatter treeFormatter) { - try (ObjectInserter inserter = repository.getObjectDatabase().newInserter()) { - return Result.ok(inserter.insert(treeFormatter)); - } catch (IOException e) { - return Result.error(e); - } + return Result.ok(repository.getObjectDatabase()) + .map(ObjectDatabase::newInserter) + .andThen(inserter -> () -> inserter.insert(treeFormatter)); } }