Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7083187

Class CSS.CssValue is missing implementations of equals() and hashCode()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 22
    • 7
    • client-libs
    • b03
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.7.0_02-ea"
      Java(TM) SE Runtime Environment (build 1.7.0_02-ea-b02)
      Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      javax.swing.text.html.CSS.CssValue is the base class of all values for CSS attributes. CSS attributes are usually stored as key/value pairs in AttributeSet-s. Two AttributeSet-s can be compared using the AttributeSet.isEqual() method. In case of CSS attributes this test may fail due to the missing implementation of equals() and hashCode() for class CssValue and its subclasses.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached test.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The test should print out "a is equal b".

      ACTUAL -
      The test prints out "a is NOT equal b".

      The two AttributeSet-s a and b in the example should be equal. The test fails as using StyleSheet.addCSSAttribute() wraps the value (i.e. 42) in a new CSS.FontSize instance. Fixing this is important for HTMLWriter!

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.text.SimpleAttributeSet;
      import javax.swing.text.html.CSS;
      import javax.swing.text.html.StyleSheet;


      public class Test {
        
        public static void main(String[] args) {
          StyleSheet ss = new StyleSheet();
          String fontSize = "42";
          
          SimpleAttributeSet a = new SimpleAttributeSet();
          ss.addCSSAttribute( a, CSS.Attribute.FONT_SIZE, fontSize);
          
          SimpleAttributeSet b = new SimpleAttributeSet();
          ss.addCSSAttribute( b, CSS.Attribute.FONT_SIZE, fontSize);
          
          if (a.isEqual( b) ) System.out.println( "a is equal b"); else System.out.println( "a is NOT equal b");
        }

      }
      ---------- END SOURCE ----------

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: