{"record":{"id":"3426a0d36a3c8a20","repo":"stanfordnlp/CoreNLP","slug":"invalid-hex-color-for-green-g","errorCode":null,"errorMessage":"invalid hex color for green\"+g","messagePattern":"invalid hex color for green\"\\+g","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/NERGUI.java","lineNumber":593,"sourceCode":"    }\n\n    JScrollPane scrollPane = new JScrollPane(editorPane);\n    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);\n\n    editorPane.setEditable(true);\n\n  }\n\n  public static String colorToHTML(Color color) {\n    String r = Integer.toHexString(color.getRed());\n    if (r.length() == 0) { r = \"00\"; }\n    else if (r.length() == 1) { r = \"0\" + r; }\n    else if (r.length() > 2) { throw new IllegalArgumentException(\"invalid hex color for red\"+r); }\n\n    String g = Integer.toHexString(color.getGreen());\n    if (g.length() == 0) { g = \"00\"; }\n    else if (g.length() == 1) { g = \"0\" + g; }\n    else if (g.length() > 2) { throw new IllegalArgumentException(\"invalid hex color for green\"+g); }\n\n    String b = Integer.toHexString(color.getBlue());\n    if (b.length() == 0) { b = \"00\"; }\n    else if (b.length() == 1) { b = \"0\" + b; }\n    else if (b.length() > 2) { throw new IllegalArgumentException(\"invalid hex color for blue\"+b); }\n\n    return \"#\"+r+g+b;\n  }\n\n  static class ColorIcon implements Icon {\n    Color color;\n\n    public ColorIcon(Color c) {\n      color = c;\n    }\n\n    public void paintIcon(Component c, Graphics g, int x, int y) {\n      g.setColor(color);","sourceCodeStart":575,"sourceCodeEnd":611,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/NERGUI.java#L575-L611","documentation":"NERGUI.colorToHTML throws IllegalArgumentException when the green channel's hex string is longer than 2 characters. Like the red check, this is a defensive invariant that only fires for a Color with a green component outside 0-255 (possible only via a custom Color subclass or bad mock).","triggerScenarios":"Calling colorToHTML with a Color whose getGreen() returns a value whose hex string exceeds 2 chars, i.e. outside 0-255 — practically only a Color subclass or test stub.","commonSituations":"Test doubles with out-of-range channel values, or custom Color implementations computing channels incorrectly.","solutions":["Use a standard java.awt.Color with all channels within 0-255.","Validate channels before constructing the Color.","Switch to String.format(\"#%02x%02x%02x\", ...) which handles the formatting without throwing."],"exampleFix":"// before\nthrow new IllegalArgumentException(\"invalid hex color for green\"+g);\n// after\ng = g.substring(g.length()-2); // or String.format formatting","handlingStrategy":"type-guard","validationCode":"static boolean isValidColor(Color c) {\n  return c.getGreen() >= 0 && c.getGreen() <= 255 && c.getRed() >= 0 && c.getRed() <= 255 && c.getBlue() >= 0 && c.getBlue() <= 255;\n}","typeGuard":"static boolean isStandardColor(Color c) { return c.getClass() == java.awt.Color.class; }","tryCatchPattern":"try {\n  String html = NERGUI.colorToHTML(color);\n} catch (IllegalArgumentException e) {\n  String html = String.format(\"#%02x%02x%02x\", color.getRed(), color.getGreen(), color.getBlue());\n}","preventionTips":["Use plain java.awt.Color instances.","Clamp green channel values before constructing colors.","Prefer String.format for conversion."],"tags":["swing","gui","illegal-argument","color","java"],"backgroundTag":"value-out-of-range","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}