FP on S1905 when casting null to (Class<?>)

Description

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(); } }

Activity

Michael GumowskiDecember 8, 2023 at 10:00 AM

Pinned fields
Click on the next to a field label to start pinning.

Details

Assignee

Reporter

Components

Priority

Sentry

Created December 8, 2023 at 10:00 AM
Updated September 23, 2024 at 8:46 AM