junit-team/junit5 · error · IllegalArgumentException

Could not open color palette properties file

Error message

Could not open color palette properties file

What it means

Thrown by getProperties(Path) at ColorPalette.java:117-123 when constructing a new FileReader(path.toFile(), UTF_8) fails with an IOException (e.g. file not found, permission denied). It is wrapped in an IllegalArgumentException. This is the file-access variant; the read-content variant is error 101.

Source

Thrown at junit-platform-console/src/main/java/org/junit/platform/console/output/ColorPalette.java:122

	}

	private static Properties getProperties(Reader reader) {
		Properties properties = new Properties();
		try {
			properties.load(reader);
		}
		catch (IOException e) {
			throw new IllegalArgumentException("Could not read color palette properties", e);
		}
		return properties;
	}

	private static Properties getProperties(Path path) {
		try (FileReader fileReader = new FileReader(path.toFile(), StandardCharsets.UTF_8)) {
			return getProperties(fileReader);
		}
		catch (IOException e) {
			throw new IllegalArgumentException("Could not open color palette properties file", e);
		}
	}

	public String paint(Style style, String text) {
		return this.disableAnsiColors || style == Style.NONE ? text
				: getAnsiFormatter(style) + text + getAnsiFormatter(Style.NONE);
	}

	private String getAnsiFormatter(Style style) {
		return "\u001B[%sm".formatted(this.colorsToAnsiSequences.get(style));
	}

}

View on GitHub (pinned to 956246301e)

Solutions

  1. Verify the file exists and is a regular readable file: Files.isReadable(path) && Files.isRegularFile(path) before constructing.
  2. Use an absolute path or resolve the path explicitly against the intended base directory.
  3. Check the caused-by IOException for the precise reason (NoSuchFileException, AccessDeniedException, etc.) and address it.
  4. Confirm the path passed to the console launcher's palette option is correct and on the local filesystem.

Example fix

// before
Path p = Path.of("palette.properties"); // wrong cwd
ColorPalette palette = new ColorPalette(p); // throws

// after
Path p = Path.of(System.getProperty("user.dir")).resolve("config/palette.properties");
if (!Files.isReadable(p)) throw new IllegalStateException("palette not readable: " + p);
ColorPalette palette = new ColorPalette(p);
Defensive patterns

Strategy: validation

Validate before calling

Path palettePath = ...;
if (!Files.isReadable(palettePath) || !Files.isRegularFile(palettePath)) {
    throw new IllegalArgumentException("palette file missing/unreadable: " + palettePath);
}
ColorPalette palette = new ColorPalette(palettePath);

Try / catch

try {
    return new ColorPalette(palettePath);
} catch (IllegalArgumentException e) {
    throw new IllegalStateException("Cannot load palette from " + palettePath, e.getCause());
}

Prevention

When it happens

Trigger: Calling new ColorPalette(path) where 'path' does not exist, is a directory rather than a regular file, is not readable due to OS permissions, or refers to a path on a filesystem that is unavailable. Triggered directly by the public ColorPalette(Path) constructor.

Common situations: Passing a relative path resolved against an unexpected working directory; pointing the console launcher's --color-palette option at a missing file; file deleted between discovery and read; running under a security manager / container that restricts file access; typo in the path string.

Related errors


AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04). Data as JSON: /data/errors/56a7b19e70853a0c.json. Report an issue: GitHub.