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

SimpleAttributeSet.isEqual may throw NPE instead of returning result

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P5 P5
    • tbd
    • 8, 11, 17, 20, 21
    • client-libs

      The implementation of SimpleAttributeSet.containsAttributes does not check for a null value of an attribute which results in throwing NullPointerException.

      Steps to reproduce:
      Run the attached AttributeSetCompare.java test.

      Expected output:
      true
      true

      Actual output:
      Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Object.equals(Object)" because the return value of "javax.swing.text.AttributeSet.getAttribute(Object)" is null
      at java.desktop/javax.swing.text.SimpleAttributeSet.containsAttributes(SimpleAttributeSet.java:182)
      at java.desktop/javax.swing.text.SimpleAttributeSet.isEqual(SimpleAttributeSet.java:119)
      at AttributeSetCompare.main(AttributeSetCompare.java:32)


      If you change the value of the attribute for `b` to a non-null value (for example "value"), the expected output would be:
      false
      false

      whereas the actual output is:
      false
      Exception in thread "main" java.lang.NullPointerException: ...

            rmahajan Rajat Mahajan
            aivanov Alexey Ivanov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: