Skip to content

UnnecessaryLocalRule for variable in a try-catch-with-resources statement #1517

@volodya-lombrozo

Description

@volodya-lombrozo

I have the following code:

private static long folderSizeInMb(final Path path) throws IOException {
        try (Stream<Path> paths = Files.walk(path)) {
            return paths.filter(Files::isRegularFile).mapToLong(
                p -> {
                    try {
                        return Files.size(p);
                    } catch (final IOException exception) {
                        throw new IllegalStateException(
                            String.format("Failed to calculate size in %s", p),
                            exception
                        );
                    }
                }
            ).sum() / 1024L / 1024L;
        }
     }

qulice complaints on the paths variable with the UnnessaryLocalRule check, because the variable is mentioned only once in the code. However, we can't just remove it, because it's Java syntax for try-catch-with-resources statement.

Expected behaviour:
quilice doesn't complain on variables declared in try-catch-with-resources.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions