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 flags this with Either log or rethrow this exception. That makes sense to us so we added e to the logger line:
LOGGER.info("Could not retrieve from file system, trying classpath. If the exception is 'Missing scheme' this can be ignored", e);
While this fixed the sonar issue, and indeed gives us a bit more useful information, we are now flooded with a 40 line stack trace. (and the method is called a LOT )
Is it possible to have the best of both worlds? Like having the error logged, but only part of it (actually, just the first two lines is fine), and without being flagged by SonarQube?