Skip to:
In the example below, SONARLINT suggests removing the type cast on null. However, doing so would lead to a compilation failure.
List<Class<?>> m(Path path) throws IOException { try (var stream = Files.walk(path)) { return stream.map(p -> { var className = p.toString(); try { return Class.forName(className); } catch (ClassNotFoundException e) { return (Class<?>) null; // FP, if we remove the type cast the code doesn't compile } }).toList(); } }
Useful links:
RSPEC: https://sonarsource.github.io/rspec/#/rspec/S1905
Legacy RSPEC ticket: https://sonarsource.atlassian.net/browse/RSPEC-1905#icft=RSPEC-1905
In the example below, SONARLINT suggests removing the type cast on null. However, doing so would lead to a compilation failure.
List<Class<?>> m(Path path) throws IOException { try (var stream = Files.walk(path)) { return stream.map(p -> { var className = p.toString(); try { return Class.forName(className); } catch (ClassNotFoundException e) { return (Class<?>) null; // FP, if we remove the type cast the code doesn't compile } }).toList(); } }