【发布时间】:2021-04-24 08:48:59
【问题描述】:
private static InputStream getFileFromClassPathOrFileSystem(String path) {
try {
//try to get from something like file:///some/path, and if missing Scheme exception, go to catch clause
return Files.newInputStream(Paths.get(URI.create(path)));
} catch (IllegalArgumentException | IOException e) {
LOGGER.info("Could not retrieve from file system, trying classpath. If the exception is 'Missing scheme' this can be ignored");
return Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
}
}
SonarQube 使用 Either log or rethrow this exception 标记此问题。这对我们来说很有意义,所以我们将e 添加到记录器行:
LOGGER.info("Could not retrieve from file system, trying classpath. If the exception is 'Missing scheme' this can be ignored", e);
虽然这解决了声纳问题,并且确实为我们提供了更多有用的信息,但我们现在充斥着 40 行的堆栈跟踪。 (并且该方法被称为 LOT ??????)
有没有可能两全其美?就像记录了错误,但只有部分错误(实际上,只有前两行很好),并且没有被 SonarQube 标记?
【问题讨论】:
标签: java exception logging sonarqube