junit-team/junit5 · error · IllegalArgumentException

Could not read color palette properties

Error message

Could not read color palette properties

What it means

Thrown when Properties.load(Reader) raises an IOException while reading a color palette from an in-memory Reader. The constructor chain ColorPalette(Reader) -> getProperties(Reader) (line 106) catches IOException and wraps it in an IllegalArgumentException with this message. It is distinct from the file-open error (102) which fires earlier when the FileReader itself cannot be created.

Source

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

		this.colorsToAnsiSequences = colorsToAnsiSequences;
		this.disableAnsiColors = disableAnsiColors;
	}

	private static Map<Style, String> toOverrideMap(Properties properties) {
		Map<String, String> upperCaseProperties = properties.entrySet().stream().collect(Collectors.toMap(
			entry -> ((String) entry.getKey()).toUpperCase(Locale.ROOT), entry -> (String) entry.getValue()));

		return Arrays.stream(Style.values()).filter(style -> upperCaseProperties.containsKey(style.name())).collect(
			Collectors.toMap(Function.identity(), style -> upperCaseProperties.get(style.name())));
	}

	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);
	}

View on GitHub (pinned to 956246301e)

Solutions

  1. Ensure the Reader supplied to the constructor is open and positioned at the start before construction.
  2. Use ColorPalette(Path) instead of ColorPalette(Reader) so the library handles file opening and UTF-8 decoding consistently.
  3. Inspect the caused-by exception (getMessage() of the wrapped IOException) to find the real I/O fault and fix that root cause.
  4. Do not reuse the same Reader instance across multiple ColorPalette constructions; create a fresh one each time.

Example fix

// before
Reader reader = Files.newBufferedReader(path); // ... later closed elsewhere
ColorPalette palette = new ColorPalette(reader); // IOException -> IAE

// after
ColorPalette palette = new ColorPalette(path); // library owns open/close, UTF-8
Defensive patterns

Strategy: validation

Validate before calling

if (reader == null) throw new IllegalArgumentException("reader null");
// simplest: prefer the Path overload which the library validates itself
ColorPalette palette = Files.exists(path) ? new ColorPalette(path) : ColorPalette.DEFAULT;

Try / catch

try {
    return new ColorPalette(reader);
} catch (IllegalArgumentException e) {
    log.error("palette read failed: {}", e.getCause().toString());
    return ColorPalette.DEFAULT; // fallback only when explicitly desired
}

Prevention

When it happens

Trigger: Calling new ColorPalette(reader) where the Reader throws during properties loading, e.g. a Reader backed by a closed stream, a Reader over a malformed/unexpected encoding, or a Reader whose underlying source disappears mid-read. Reachable transitively from ColorPalette(Path) and ColorPalette(Properties) only insofar as the Reader path is exercised.

Common situations: Passing a Reader that has already been closed; reusing a BufferedReader across multiple consumers; reading from a network/pipe-backed Reader that is broken; supplying a Reader with an encoding incompatible with java.util.Properties' expected ISO-8859-1.

Related errors


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