Skip to content

SystemPath throws InvalidPathException on a single malformed PATH entry, aborting all of IDEasy #2088

Description

@maybeec

Actual behavior

If the PATH environment variable contains a single segment that is not a syntactically valid path for the current OS (e.g. a segment containing an illegal character such as a newline on Windows, or a NUL byte on any OS), IDEasy fails completely instead of ignoring that one entry.

SystemPath splits PATH on the path separator and calls Path.of(segment) for every segment without guarding against java.nio.file.InvalidPathException:

// cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java
String[] envPaths = envPath.split(Character.toString(pathSeparator));
for (String segment : envPaths) {
  Path path = Path.of(segment);   // <-- throws InvalidPathException, aborting the whole constructor
  String tool = getTool(path, ideRoot);
  if (tool == null) {
    this.paths.add(path);
  }
}

Because SystemPath is constructed during context setup, this unchecked exception propagates up and aborts the entire IDEasy invocation. A single malformed PATH entry takes the whole tool down.

Observed stack trace (Windows):

java.nio.file.InvalidPathException: Trailing char <\n> at index 43: IDE environment variables have been set for ... in workspace main
	at java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:203)
	at java.base/java.nio.file.Path.of(Path.java:148)
	at com.devonfw.tools.ide.common.SystemPath.<init>(SystemPath.java:99)

Reproduce

Unit-level (deterministic, OS-independent), e.g. a PATH entry containing an illegal NUL character:

String envPath = "C:\\Tools\\bin" + ';' + ("broken" + (char) 0 + "entry") + ';' + "C:\\Other\\bin";
new SystemPath(context, envPath, ideRoot, softwarePath, ';', List.of());
// -> throws InvalidPathException instead of skipping the single bad entry

Real-world trigger that surfaced this: on Windows a PATH value ended up containing an embedded newline / non-path text (a stdout line leaking into PATH, e.g. the human-readable activation banner "IDE environment variables have been set for ... in workspace main" followed by a newline). Any subsequent ide ... command then aborts before doing anything useful.

Expected behavior

A single malformed PATH entry should not break IDEasy. The invalid entry should be skipped and a warning logged, while all valid entries continue to be processed normally — consistent with how IDEasy already handles other malformed configuration (e.g. invalid variable definitions are skipped with a warning rather than aborting).

Expected log (example):

WARNING Ignoring invalid PATH entry 'broken<NUL>entry' - Illegal char <NUL> at index 6: broken<NUL>entry

IDEasy status

Reproduced against current main (version dev-SNAPSHOT).
Your operating system is windows(10.0)@x64 [Windows 11@amd64]

Comments/Hints

  • Root cause is the unguarded Path.of(segment) at cli/src/main/java/com/devonfw/tools/ide/common/SystemPath.java:99.
  • Suggested fix: wrap the per-segment Path.of(...) in a try/catch (InvalidPathException), log a warning via SLF4J, and continue to the next segment. Small, localized robustness improvement (defense-in-depth); no behavior change for well-formed PATH values.
  • This is a pre-existing latent robustness gap; it is only exposed by a corrupted environment, not caused by it.

Metadata

Metadata

Assignees

Labels

environmentEnvironmentCommandlet, env variables, path, etc.ready-to-implementwindowsspecific for Microsoft Windows OS

Type

No fields configured for Bug.

Projects

Status
🏗 In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions