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

In Java 8 java.awt.datatransfer.DataFlavor.equals is no longer symmetric

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b12
    • CPU:
      x86_64
    • OS:
      linux

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0"
        Java(TM) SE Runtime Environment (build 1.8.0-b132)
        Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

        java version "1.8.0"
        Java(TM) SE Runtime Environment (build 1.8.0-b132)
        Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Linux devel 3.11.0-18-generic #32-Ubuntu SMP Tue Feb 18 21:11:14 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

        Microsoft Windows [Versjon 6.1.7601]

        A DESCRIPTION OF THE PROBLEM :
        In Java 8 java.awt.datatransfer.DataFlavor.equals fails to honor the equals contract by no longer beeing symmetric as the JavaDoc descibes it:
        "It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true."

        This occurs when testing two DataFlavors of the MIME-type "text/html" for equality and only one of them has the "document" parameter set.

        REGRESSION. Last worked in version 7u51

        ADDITIONAL REGRESSION INFORMATION:
        java version "1.7.0_51"
        Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
        Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        javac DataFlavorTest.java
        java DataFlavorTest

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Equals is symmetric for minimalHtmlFlavor and allHtmlFlavor
        Equals is symmetric for minimalHtmlFlavor and fragmentHtmlFlavor
        Equals is symmetric for minimalHtmlFlavor and selectionHtmlFlavor

        ACTUAL -
        Equals not symmetric for minimalHtmlFlavor and allHtmlFlavor
        Equals not symmetric for minimalHtmlFlavor and fragmentHtmlFlavor
        Equals not symmetric for minimalHtmlFlavor and selectionHtmlFlavor


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.datatransfer.DataFlavor;

        public class DataFlavorTest {

            public static void main(String[] args) throws ClassNotFoundException {
                equalsShouldBySymetric();
            }

            public static void equalsShouldBySymetric() throws ClassNotFoundException {
                DataFlavor minimalHtmlFlavor = new DataFlavor("text/html; class=java.lang.String");

                // Static DataFlavors introduced in Java 8
                DataFlavor allHtmlFlavor = new DataFlavor("text/html; class=java.lang.String;document=all;charset=Unicode");
                DataFlavor fragmentHtmlFlavor = new DataFlavor("text/html; class=java.lang.String;document=fragment;charset=Unicode");
                DataFlavor selectionHtmlFlavor = new DataFlavor("text/html; class=java.lang.String;document=selection;charset=Unicode");

                if ((minimalHtmlFlavor.equals(allHtmlFlavor) == allHtmlFlavor.equals(minimalHtmlFlavor))) {
                    System.out.println("Equals is symmetric for minimalHtmlFlavor and allHtmlFlavor");
                } else {
                    System.out.println("Equals not symmetric for minimalHtmlFlavor and allHtmlFlavor");
                }

                if ((minimalHtmlFlavor.equals(fragmentHtmlFlavor) == fragmentHtmlFlavor.equals(minimalHtmlFlavor))) {
                    System.out.println("Equals is symmetric for minimalHtmlFlavor and fragmentHtmlFlavor");
                } else {
                    System.out.println("Equals not symmetric for minimalHtmlFlavor and fragmentHtmlFlavor");
                }

                if ((minimalHtmlFlavor.equals(selectionHtmlFlavor) == selectionHtmlFlavor.equals(minimalHtmlFlavor))) {
                    System.out.println("Equals is symmetric for minimalHtmlFlavor and selectionHtmlFlavor");
                } else {
                    System.out.println("Equals not symmetric for minimalHtmlFlavor and selectionHtmlFlavor");
                }
            }

        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        We could invert the equals check in our part of the code and thereby avoiding the comparison of the document parameter

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  pchelko Petr Pchelko (Inactive)
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: