{"id":"0982fd0d51400e50","repo":"junit-team/junit5","slug":"could-not-read-color-palette-properties","errorCode":null,"errorMessage":"Could not read color palette properties","messagePattern":"Could not read color palette properties","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"junit-platform-console/src/main/java/org/junit/platform/console/output/ColorPalette.java","lineNumber":112,"sourceCode":"\t\tthis.colorsToAnsiSequences = colorsToAnsiSequences;\n\t\tthis.disableAnsiColors = disableAnsiColors;\n\t}\n\n\tprivate static Map<Style, String> toOverrideMap(Properties properties) {\n\t\tMap<String, String> upperCaseProperties = properties.entrySet().stream().collect(Collectors.toMap(\n\t\t\tentry -> ((String) entry.getKey()).toUpperCase(Locale.ROOT), entry -> (String) entry.getValue()));\n\n\t\treturn Arrays.stream(Style.values()).filter(style -> upperCaseProperties.containsKey(style.name())).collect(\n\t\t\tCollectors.toMap(Function.identity(), style -> upperCaseProperties.get(style.name())));\n\t}\n\n\tprivate static Properties getProperties(Reader reader) {\n\t\tProperties properties = new Properties();\n\t\ttry {\n\t\t\tproperties.load(reader);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new IllegalArgumentException(\"Could not read color palette properties\", e);\n\t\t}\n\t\treturn properties;\n\t}\n\n\tprivate static Properties getProperties(Path path) {\n\t\ttry (FileReader fileReader = new FileReader(path.toFile(), StandardCharsets.UTF_8)) {\n\t\t\treturn getProperties(fileReader);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new IllegalArgumentException(\"Could not open color palette properties file\", e);\n\t\t}\n\t}\n\n\tpublic String paint(Style style, String text) {\n\t\treturn this.disableAnsiColors || style == Style.NONE ? text\n\t\t\t\t: getAnsiFormatter(style) + text + getAnsiFormatter(Style.NONE);\n\t}\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-platform-console/src/main/java/org/junit/platform/console/output/ColorPalette.java#L94-L130","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the Reader supplied to the constructor is open and positioned at the start before construction.","Use ColorPalette(Path) instead of ColorPalette(Reader) so the library handles file opening and UTF-8 decoding consistently.","Inspect the caused-by exception (getMessage() of the wrapped IOException) to find the real I/O fault and fix that root cause.","Do not reuse the same Reader instance across multiple ColorPalette constructions; create a fresh one each time."],"exampleFix":"// before\nReader reader = Files.newBufferedReader(path); // ... later closed elsewhere\nColorPalette palette = new ColorPalette(reader); // IOException -> IAE\n\n// after\nColorPalette palette = new ColorPalette(path); // library owns open/close, UTF-8","handlingStrategy":"validation","validationCode":"if (reader == null) throw new IllegalArgumentException(\"reader null\");\n// simplest: prefer the Path overload which the library validates itself\nColorPalette palette = Files.exists(path) ? new ColorPalette(path) : ColorPalette.DEFAULT;","typeGuard":null,"tryCatchPattern":"try {\n    return new ColorPalette(reader);\n} catch (IllegalArgumentException e) {\n    log.error(\"palette read failed: {}\", e.getCause().toString());\n    return ColorPalette.DEFAULT; // fallback only when explicitly desired\n}","preventionTips":["Do not close or reuse the Reader before construction completes.","Prefer ColorPalette(Path) over ColorPalette(Reader) to delegate file handling.","Always inspect the caused-by IOException for the real I/O fault."],"tags":["junit-platform","console","io","color-palette","configuration"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}