United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 5087905 REGRESSION: CSS cause NPE for unknown colours
5087905 : REGRESSION: CSS cause NPE for unknown colours

Details
Type:
Bug
Submit Date:
2004-08-17
Status:
Resolved
Updated Date:
2004-10-25
Project Name:
JDK
Resolved Date:
2004-09-22
Component:
client-libs
OS:
windows_2000
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:
5.0u1

Related Reports
Backport:

Sub Tasks

Description
Name: js151677			Date: 08/17/2004


FULL PRODUCT VERSION :
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
CSS cause NPE for unknown colours

The CSS spec says that unknown values need to be ignored.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run code

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the default colour to be used

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NullPointerException

	at javax.swing.text.html.CSS.stringToColor(CSS.java:1049)

	at javax.swing.text.html.CSS$ColorValue.parseCssValue(CSS.java:2001)

	at javax.swing.text.html.CSS.getInternalCSSValue(CSS.java:532)

	at javax.swing.text.html.CSS.addInternalCSSValue(CSS.java:516)

	at javax.swing.text.html.StyleSheet.addCSSAttribute(StyleSheet.java:465)

	at javax.swing.text.html.StyleSheet$CssParser.handleValue(StyleSheet.java:3146)

	at javax.swing.text.html.CSSParser.parseDeclaration(CSSParser.java:341)

	at javax.swing.text.html.CSSParser.parseDeclarationBlock(CSSParser.java:308)

	at javax.swing.text.html.CSSParser.parseRuleSet(CSSParser.java:255)

	at javax.swing.text.html.CSSParser.getNextStatement(CSSParser.java:161)

	at javax.swing.text.html.CSSParser.parse(CSSParser.java:136)

	at javax.swing.text.html.StyleSheet$CssParser.parse(StyleSheet.java:3068)

	at javax.swing.text.html.StyleSheet.addRule(StyleSheet.java:273)

	at javax.swing.text.html.HTMLDocument$HTMLReader.addCSSRules(HTMLDocument.java:3374)

	at javax.swing.text.html.HTMLDocument$HTMLReader$HeadAction.end(HTMLDocument.java:2526)

	at javax.swing.text.html.HTMLDocument$HTMLReader.handleEndTag(HTMLDocument.java:2264)

	at javax.swing.text.html.parser.DocumentParser.handleEndTag(DocumentParser.java:223)

	at javax.swing.text.html.parser.Parser.parse(Parser.java:2132)

	at javax.swing.text.html.parser.DocumentParser.parse(DocumentParser.java:105)

	at javax.swing.text.html.parser.ParserDelegator.parse(ParserDelegator.java:73)

	at javax.swing.text.html.HTMLEditorKit.read(HTMLEditorKit.java:230)

	at javax.swing.JEditorPane.setText(JEditorPane.java:1311)

	at javax.swing.JEditorPane.<init>(JEditorPane.java:264)
1, mixed mode, sharing)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;

public class Test {
  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(new JEditorPane("text/html",
      "<HTML>" +
        "<HEAD>" +
          "<TITLE>CSS Test</title>" +
          "<STYLE TYPE=\"text/css\">" +
            "H1 { color: orange }" +
          "</style>" +
        "</head>" +
        "<BODY>" +
          "<H1>This might be orange or the default colour</h1>" +
        "</body>" +
      "</html>"));
    frame.setSize(500, 500);
    frame.setVisible(true);
  }
}
---------- END SOURCE ----------

Release Regression From : 1.4.2_05
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Incident Review ID: 297283) 
======================================================================
###@###.### 2004-09-09

                                    

Comments
SUGGESTED FIX

------- CSS.java -------
172c172
<           new Attribute("border-color", null, false);
---
>           new Attribute("border-color", "black", false);
202c202
<           new Attribute("color", null, true);
---
>           new Attribute("color", "black", true);
                                     
2004-09-28
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
1.5.0_01
mustang

FIXED IN:
1.5.0_01
mustang

INTEGRATED IN:
1.5.0_01
mustang


                                     
2004-09-28
EVALUATION

will work on this bug for the next release
###@###.### 2004-08-18

this bug is a regression introduced by the fix for 4845362 
( http://sa.sfbay.sun.com/swing/tiger/4845362.0/ )

conv.parseCssValue(key.getDefaultValue()) 
Default value for color is null.
stringToColor can not take null and thus NPE

Simple fix could be to assign default value to color.

*** /tmp/geta11725	Wed Sep  8 03:00:38 2004
--- CSS.java	Wed Sep  8 02:54:00 2004
***************
*** 199,205 ****
  	    new Attribute("clear", "none", false);
  
  	public static final Attribute COLOR =
! 	    new Attribute("color", null, true);
  
  	public static final Attribute DISPLAY =
  	    new Attribute("display", "block", false);
--- 199,205 ----
  	    new Attribute("clear", "none", false);
  
  	public static final Attribute COLOR =
! 	    new Attribute("color", "black", true);
  
  	public static final Attribute DISPLAY =
  	    new Attribute("display", "block", false);


============

Color is not the only attribute with null defalut value. We might have to handle others too.
Reassigning this bug to the fixer of 4845362 ###@###.###

###@###.### 2004-09-08

I suggest specifying "black" as default value for 'color' and 'border-color'.
Default values for 'font-family' and 'text-align' are user agent dependent and should not be hardcoded in CSS. There are many others attributes with null defalut values, but they are composite (like 'border' or 'margin'), and need no default value.
###@###.### 2004-09-08
                                     
2004-09-08



Hardware and Software, Engineered to Work Together