Problem
The project coding conventions (documentation/contributing/coding-conventions.adoc, section "Obsolete APIs") state:
java.io.File - use java.nio.file.Path
This is enforced by Checkstyle (IllegalImport in checkstyle.xml). However, Checkstyle in CI only runs on changed files, so a number of pre-existing import java.io.File; violations are currently latent — they will fail the build the moment their file is next edited (as just happened in #2088 / PR #2089 for SystemPath.java).
This issue tracks cleaning up the remaining non-compliant java.io.File usages so they follow the NIO/Path convention.
Affected files & classification
All cases have a convention-compliant substitute. Note that RandomAccessFile, FileLock and Apache Commons FileUtils are not banned — only java.io.File (the path abstraction) is. Where those APIs need a File, it can be obtained inline via path.toFile(), which does not trigger IllegalImport (no import).
A) File.separatorChar constant (test mocks)
cli/src/test/java/com/devonfw/tools/ide/context/PipRepositoryMock.java
cli/src/test/java/com/devonfw/tools/ide/context/MvnRepositoryMock.java
cli/src/test/java/com/devonfw/tools/ide/context/NpmRepositoryMock.java
Use: rel.toString().replace(File.separatorChar, '/') (normalize OS separators to /).
Substitute: System.getProperty("file.separator").charAt(0), or NIO-native FileSystems.getDefault().getSeparator(), or build the string by joining the Path name elements with / (fully OS-independent).
B) Real java.io.File object usage
cli/src/main/java/com/devonfw/tools/ide/locking/EclipseWorkspaceLockChecker.java (main) — new File(args[0]), isLocked(File), new RandomAccessFile(file, ...).
Substitute: change signature to isLocked(Path), Path.of(args[0]), Files.isRegularFile(...); feed RandomAccessFile via lockfile.toFile() inline (or switch to FileChannel.open(...)). NB: this logic is duplicated in Eclipse.java#isLocked(Path) (see C) — could be de-duplicated.
cli/src/test/java/com/devonfw/tools/ide/locking/EclipseWorkspaceLockCheckerTest.java (test) — File.createTempFile, new File, .delete().
Substitute: Files.createTempFile(...), Path.of(...), Files.deleteIfExists(...); RandomAccessFile via .toFile() inline. Follows the isLocked signature change above.
gui/src/test/java/com/devonfw/ide/gui/context/ProjectManagerTest.java (gui test) — ...toFile() locals with .createNewFile() and .renameTo(...).
Substitute: Files.createFile(path) and Files.move(src, tgt); the FileUtils.copyDirectory/deleteDirectory calls keep their inline .toFile().
C) Stale javadoc only (genuine doc bug)
cli/src/main/java/com/devonfw/tools/ide/tool/eclipse/Eclipse.java (main) — the File import survives only because of a stale {@link File} javadoc on isLocked(Path lockfile), whose parameter is already Path.
Substitute: fix javadoc to {@link Path} and drop the import. Zero functional change.
Acceptance criteria
- No
import java.io.File; remains in the codebase (grep -rn "import java.io.File;" --include=*.java returns nothing).
- All replacements use
java.nio.file.Path / Files / system-property (or FileSystems) separators per the coding conventions.
- All existing tests still pass;
mvn checkstyle:check passes for the changed files.
Problem
The project coding conventions (
documentation/contributing/coding-conventions.adoc, section "Obsolete APIs") state:This is enforced by Checkstyle (
IllegalImportincheckstyle.xml). However, Checkstyle in CI only runs on changed files, so a number of pre-existingimport java.io.File;violations are currently latent — they will fail the build the moment their file is next edited (as just happened in #2088 / PR #2089 forSystemPath.java).This issue tracks cleaning up the remaining non-compliant
java.io.Fileusages so they follow the NIO/Pathconvention.Affected files & classification
All cases have a convention-compliant substitute. Note that
RandomAccessFile,FileLockand Apache CommonsFileUtilsare not banned — onlyjava.io.File(the path abstraction) is. Where those APIs need aFile, it can be obtained inline viapath.toFile(), which does not triggerIllegalImport(noimport).A)
File.separatorCharconstant (test mocks)cli/src/test/java/com/devonfw/tools/ide/context/PipRepositoryMock.javacli/src/test/java/com/devonfw/tools/ide/context/MvnRepositoryMock.javacli/src/test/java/com/devonfw/tools/ide/context/NpmRepositoryMock.javaUse:
rel.toString().replace(File.separatorChar, '/')(normalize OS separators to/).Substitute:
System.getProperty("file.separator").charAt(0), or NIO-nativeFileSystems.getDefault().getSeparator(), or build the string by joining thePathname elements with/(fully OS-independent).B) Real
java.io.Fileobject usagecli/src/main/java/com/devonfw/tools/ide/locking/EclipseWorkspaceLockChecker.java(main) —new File(args[0]),isLocked(File),new RandomAccessFile(file, ...).Substitute: change signature to
isLocked(Path),Path.of(args[0]),Files.isRegularFile(...); feedRandomAccessFilevialockfile.toFile()inline (or switch toFileChannel.open(...)). NB: this logic is duplicated inEclipse.java#isLocked(Path)(see C) — could be de-duplicated.cli/src/test/java/com/devonfw/tools/ide/locking/EclipseWorkspaceLockCheckerTest.java(test) —File.createTempFile,new File,.delete().Substitute:
Files.createTempFile(...),Path.of(...),Files.deleteIfExists(...);RandomAccessFilevia.toFile()inline. Follows theisLockedsignature change above.gui/src/test/java/com/devonfw/ide/gui/context/ProjectManagerTest.java(gui test) —...toFile()locals with.createNewFile()and.renameTo(...).Substitute:
Files.createFile(path)andFiles.move(src, tgt); theFileUtils.copyDirectory/deleteDirectorycalls keep their inline.toFile().C) Stale javadoc only (genuine doc bug)
cli/src/main/java/com/devonfw/tools/ide/tool/eclipse/Eclipse.java(main) — theFileimport survives only because of a stale{@link File}javadoc onisLocked(Path lockfile), whose parameter is alreadyPath.Substitute: fix javadoc to
{@link Path}and drop the import. Zero functional change.Acceptance criteria
import java.io.File;remains in the codebase (grep -rn "import java.io.File;" --include=*.javareturns nothing).java.nio.file.Path/Files/ system-property (orFileSystems) separators per the coding conventions.mvn checkstyle:checkpasses for the changed files.