BasePractice / algorithms-and-data-structures-2024

Практические работы по курсу "Алгоритмы и структуры данных в системах реального времени" за 2024 год
MIT License
0 stars 9 forks source link

PMD throws false-positive CloseResource violations #13

Closed ImSpaceLover closed 3 hours ago

ImSpaceLover commented 5 hours ago

PMD sends a message saying "Ensure that resources like this InputStream object are closed after use", even though Scanner is already closing Here's the piece of code where it finds the error:

        int i = 0;
        try {
            while (i < arr.length) {
                arr[i] = sc.nextFloat();
                i+=1;
                }
            } catch (RuntimeException e) {
            throw new RuntimeException(e);
        }
        finally {
            sc.close();
        }

PMD отправляет сообщение со словами "Ensure that resources like this InputStream object are closed after use", хотя Сканнер уже закрывается Сверху часть кода, где он находит ошибку

-- Студент МИРЭА

Pastor commented 4 hours ago

Используйте конструкцию try-with-resources