Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compiler warning "Potential resource leak" #762

Merged
merged 1 commit into from
Jun 12, 2024
Merged
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 @@ -31,27 +31,29 @@ class RawThemeReaderTest {
@NonNullByDefault({})
void testLoadingThemes() throws IOException {
final var count = new AtomicInteger();
Files.list(Paths.get("../org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes")).forEach(file -> {
final var fileName = file.getFileName().toString();
if (fileName.endsWith(".json") && (fileName.contains("light") || fileName.contains("dark") || fileName.contains("black"))
|| fileName.endsWith(".tmTheme")) {
System.out.println("Parsing [" + file + "]...");
try {
final IRawTheme rawTheme = RawThemeReader.readTheme(IThemeSource.fromFile(file));
count.incrementAndGet();
assertFalse(castNonNull(rawTheme.getName()).isEmpty());
assertFalse(castNonNull(rawTheme.getSettings()).isEmpty());
for (final var setting : castNonNull(rawTheme.getSettings())) {
assertNotNull(setting.getSetting());
try (final var files = Files.list(Paths.get("../org.eclipse.tm4e.core.tests/src/main/resources/test-cases/themes"))) {
files.forEach(file -> {
final var fileName = file.getFileName().toString();
if (fileName.endsWith(".json") && (fileName.contains("light") || fileName.contains("dark") || fileName.contains("black"))
|| fileName.endsWith(".tmTheme")) {
System.out.println("Parsing [" + file + "]...");
try {
final IRawTheme rawTheme = RawThemeReader.readTheme(IThemeSource.fromFile(file));
count.incrementAndGet();
assertFalse(castNonNull(rawTheme.getName()).isEmpty());
assertFalse(castNonNull(rawTheme.getSettings()).isEmpty());
for (final var setting : castNonNull(rawTheme.getSettings())) {
assertNotNull(setting.getSetting());
}
final var theme = Theme.createFromRawTheme(rawTheme, null);
assertFalse(theme.getColorMap().isEmpty());
assertNotNull(theme.getDefaults());
} catch (final Exception ex) {
throw new RuntimeException(ex);
}
final var theme = Theme.createFromRawTheme(rawTheme, null);
assertFalse(theme.getColorMap().isEmpty());
assertNotNull(theme.getDefaults());
} catch (final Exception ex) {
throw new RuntimeException(ex);
}
}
});
});
}
System.out.println("Successfully parsed " + count.intValue() + " themes.");
assertTrue(count.intValue() > 10, "Only " + count.intValue() + " themes found, expected more than 10!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ void handle() throws IOException {
logInfo("Locating valid VSCode grammar extensions...");
final Map<String, VsCodeExtensionPackageJson> pkgJsonByExtId = new HashMap<>();
final Map<String, Path> pkgJsonPathByExtId = new HashMap<>();
try (var l = withLogIndented()) {
for (final var dir : Files.list(sourceExtensionDir).filter(Files::isDirectory).toList()) {
try (var l = withLogIndented(); var files = Files.list(sourceExtensionDir)) {
for (final var dir : files.filter(Files::isDirectory).toList()) {
final var pkgJSONPath = dir.resolve("package.json");
if (!Files.exists(pkgJSONPath)) {
logInfo("Ignoring extension directory [" + dir.getFileName() + "] - no package.json found");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.regex.Pattern;
import java.util.stream.Stream;

import com.fasterxml.jackson.annotation.JsonProperty;

Expand Down Expand Up @@ -114,10 +115,11 @@ public static GitCheckoutState gitSparseCheckout(final Path localPath, final Git
}

// delete local git repo if not in desired state
Files.walk(localPath) //
.sorted(Comparator.reverseOrder()) //
.map(Path::toFile) //
.forEach(File::delete);
try (Stream<Path> files = Files.walk(localPath)) {
files.sorted(Comparator.reverseOrder()) //
.map(Path::toFile) //
.forEach(File::delete);
}
}

Files.createDirectories(localPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ public static void execVerbose(final Path workDir, final String cmd, final Strin
}

public static Optional<Path> findFirstFile(final Path path, final Predicate<String> nameFilter) throws IOException {
return Files.list(path) //
.filter(Files::isRegularFile) //
.filter(file -> nameFilter.test(file.getFileName().toString())).findFirst();
try (Stream<Path> files = Files.walk(path)) {
return files //
.filter(Files::isRegularFile) //
.filter(file -> nameFilter.test(file.getFileName().toString())).findFirst();
}
}

public static String getFileExtension(final Path path) {
Expand All @@ -165,10 +167,11 @@ public static String getFileExtension(final String path) {

public static void rmDir(final Path dir) throws IOException {
if (Files.exists(dir)) {
Files.walk(dir) //
.sorted(Comparator.reverseOrder()) //
.map(Path::toFile) //
.forEach(File::delete);
try (Stream<Path> files = Files.walk(dir)) {
files.sorted(Comparator.reverseOrder()) //
.map(Path::toFile) //
.forEach(File::delete);
}
}
}

Expand Down
Loading