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

SystemFlavorMap API Inconsistency Between Documentation and Implementation

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The SystemFlavorMap class exhibits inconsistent behavior regarding mapping directionality. While the documentation for setFlavorsForNative() explicitly states that mappings "will only be established in one direction," testing reveals that bidirectional mappings are automatically created in the default case, contradicting the documentation.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Copy
      Setting one-way mapping from native to flavor...
      Reverse mappings exist despite documentation saying they shouldn't:
      []

      Attempting to create true one-way mapping...
      Reverse mappings after clearing and setting one-way mapping:
      []
      ACTUAL -
      Setting one-way mapping from native to flavor...
      Reverse mappings exist despite documentation saying they shouldn't:
      [JAVA_DATAFLAVOR:application/x-java-serialized-object; class=SystemFlavorMapBugTest$CustomTestClass]

      Attempting to create true one-way mapping...
      Reverse mappings after clearing and setting one-way mapping:
      []

      ---------- BEGIN SOURCE ----------
      import java.awt.datatransfer.DataFlavor;
      import java.awt.datatransfer.SystemFlavorMap;
      import java.util.List;



      public class SystemFlavorMapBugTest {
          class CustomTestClass {}
          public static void main(String[] args) throws Exception {
              SystemFlavorMap flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
              
              String testNative = "CUSTOM_TEST_NATIVE";
              DataFlavor testFlavor = new DataFlavor(CustomTestClass.class, "custom test flavor");
              
              // Case 1: Setting one-way mapping directly
              System.out.println("Setting one-way mapping from native to flavor...");
              flavorMap.setFlavorsForNative(testNative, new DataFlavor[]{testFlavor});
              
              List<String> reverseMappings = flavorMap.getNativesForFlavor(testFlavor);
              System.out.println("Reverse mappings exist despite documentation saying they shouldn't:");
              System.out.println(reverseMappings);
              
              // Case 2: Attempting to create true one-way mapping by clearing first
              System.out.println("\nAttempting to create true one-way mapping...");
              String testNative2 = "ANOTHER_TEST_NATIVE";
              flavorMap.setNativesForFlavor(testFlavor, new String[0]);
              flavorMap.setFlavorsForNative(testNative2, new DataFlavor[]{testFlavor});
              
              reverseMappings = flavorMap.getNativesForFlavor(testFlavor);
              System.out.println("Reverse mappings after clearing and setting one-way mapping:");
              System.out.println(reverseMappings);
          }
      }
      ---------- END SOURCE ----------

            honkar Harshitha Onkar
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: