Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.sourceforge.pmd.lang.java.ast.ASTArgumentList;
import net.sourceforge.pmd.lang.java.ast.ASTBlock;
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
import net.sourceforge.pmd.lang.java.ast.ASTResource;
import net.sourceforge.pmd.lang.java.ast.ASTReturnStatement;
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
Expand All @@ -27,6 +28,10 @@ public Object visit(
final ASTVariableDeclarator variable,
final Object data
) {
// Skip variables that are declared as resources in a try-with-resources block
if (variable.ancestors(ASTResource.class).toStream().findAny().isPresent()) {
return data;
}
if (variable.getInitializer() != null) {
final String name = variableName(variable);
if (!name.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.qulice.pmd;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;

public final class ValidTryWithResources {
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("Failed", exception);
}
}
).sum() / 1024L / 1024L;
}
}
}
Loading