diff --git a/opengrok-indexer/src/main/java/org/opengrok/indexer/util/CtagsUtil.java b/opengrok-indexer/src/main/java/org/opengrok/indexer/util/CtagsUtil.java index 3c87fff0dcb..bdea93b4354 100644 --- a/opengrok-indexer/src/main/java/org/opengrok/indexer/util/CtagsUtil.java +++ b/opengrok-indexer/src/main/java/org/opengrok/indexer/util/CtagsUtil.java @@ -18,7 +18,7 @@ */ /* - * Copyright (c) 2006, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved. * Portions Copyright (c) 2019, Chris Fraire . */ package org.opengrok.indexer.util; @@ -54,6 +54,10 @@ public class CtagsUtil { public static final String SYSTEM_CTAGS_PROPERTY = "org.opengrok.indexer.analysis.Ctags"; + /** Private to enforce static. */ + private CtagsUtil() { + } + /** * Check that {@code ctags} program exists and is working. * @param ctagsBinary name of the ctags program or path @@ -163,7 +167,7 @@ public static Set getLanguages(String ctagsBinary) { Set result = new HashSet<>(); for (String lang : split) { lang = lang.trim(); - if (lang.length() > 0) { + if (!lang.isEmpty()) { result.add(lang); } } @@ -192,7 +196,7 @@ public static void deleteTempFiles() { continue; } - LOGGER.log(Level.FINER, "deleting Ctags temporary files in directory {0}", directoryName); + LOGGER.log(Level.FINER, "deleting Ctags temporary files in directory ''{0}''", directoryName); deleteTempFiles(directory); } } @@ -205,14 +209,18 @@ private static void deleteTempFiles(File directory) { return matcher.find(); }); + if (Objects.isNull(files)) { + return; + } + for (File file : files) { - if (file.isFile() && !file.delete()) { - LOGGER.log(Level.WARNING, "cannot delete file {0}", file); + if (file.isFile()) { + try { + Files.delete(file.toPath()); + } catch (IOException exception) { + LOGGER.log(Level.WARNING, String.format("cannot delete file '%s'", file), exception); + } } } } - - /** Private to enforce static. */ - private CtagsUtil() { - } }