Skip to content

Commit

Permalink
use Path.of() to avoid 'Potential resource leak' warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T authored and rgrunber committed Jan 9, 2024
1 parent 63ad336 commit 67fce40
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -345,7 +344,7 @@ public boolean hasCUDeclaringPackage(String qualifiedPackageName, Function<Compi
public char[][] listPackages() {
Set<String> packageNames = new HashSet<>();
try {
Path basePath = FileSystems.getDefault().getPath(this.path);
Path basePath = Path.of(this.path);
Files.walkFileTree(basePath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import static org.eclipse.jdt.internal.compiler.parser.TerminalTokens.TokenNameEOF;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayDeque;
Expand Down Expand Up @@ -1788,7 +1787,7 @@ private Path getFilePathFromFileName(String fileName) {
ArrayList<String> sourceClassPaths = (ArrayList<String>) this.srcClasspath;
Path filePath = null;
for (String iPath : sourceClassPaths) {
filePath = FileSystems.getDefault().getPath(this.projectPath, iPath, fileName);
filePath = Path.of(this.projectPath, iPath, fileName);
if(filePath.toFile().exists())
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -322,7 +321,7 @@ private void walkOutFiles(final String outputLocation, final Set<String> fileNam
if (!(new File(outputLocation)).exists())
return;
try {
Files.walkFileTree(FileSystems.getDefault().getPath(outputLocation), new SimpleFileVisitor<Path>() {
Files.walkFileTree(Path.of(outputLocation), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.toString().endsWith(".class")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.DirectoryNotEmptyException;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -328,7 +327,7 @@ private void walkOutFiles(final String outputLocation, final Set<String> fileNam
if (!(new File(outputLocation)).exists())
return;
try {
Files.walkFileTree(FileSystems.getDefault().getPath(outputLocation), new SimpleFileVisitor<Path>() {
Files.walkFileTree(Path.of(outputLocation), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (file.toString().endsWith(".class")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.eclipse.jdt.core.tests.model;

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;

import org.eclipse.core.resources.IWorkspaceRunnable;
Expand Down Expand Up @@ -362,7 +361,7 @@ public void testFindTypeWithUnrelatedWorkingCopy() throws Exception {
*/
public void testTransitionFromInvalidToValidJar() throws CoreException, IOException {
String transitioningJar = getExternalPath() + "transitioningJar.jar";
java.nio.file.Path transitioningJarPath = FileSystems.getDefault().getPath(transitioningJar);
java.nio.file.Path transitioningJarPath = java.nio.file.Path.of(transitioningJar);
IPath transitioningIPath = Path.fromOSString(transitioningJar);

try {
Expand Down

0 comments on commit 67fce40

Please sign in to comment.