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

SystemFlavorMap method addUnencodedNativeForFlavor() allows duplicate entries

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • client-libs
    • None
    • beta3
    • sparc
    • solaris_8
    • Verified

      SystemFlavorMap method addUnencodedNativeForFlavor() allows duplicate String native entries.

      If addUnencodedNativeForFlavor() adds the same String native multiple times, all duplicate entries will be added to the list of available natives. The documentation does not mention this particular case.

      Seems that expected behavior would be to check for duplicate entry first, and then add the String native if it's not a duplicate entry.

      Here's sample output from adding the String native "TEST NATIVE" mulitple times to a DataFlavor in the SystemFlavorMap.

      **** Printing original set of mappings

      *** Printing all String Natives
      *** Size = 1

      FILE_NAME


      **** Printing newly assigned mappings from SystemFlavorMap

      *** Printing all String Natives
      *** Size = 4

      FILE_NAME
      TEST NATIVE
      TEST NATIVE
      TEST NATIVE

      ----
      To reproduce this bug, compile and run the following sample code AddDuplicateNatives.java

      /*
        test 1.0 8/16/01
        @summary To test SystemFlavorMap method:
        
                 addUnencodedNativeForFlavor(DataFlavor flav, String nat)

                 This test will add duplicate String natives to the same DataFlavor.
                 
        @author Rick Reynaga (###@###.###) area=Clipboard
      */

      import java.awt.datatransfer.*;
      import java.util.*;

      public class AddDuplicateNatives {

          SystemFlavorMap flavorMap;
          Vector vectorFlavors;
          Vector vectorNatives1;
          Vector vectorNatives2;

          public AddDuplicateNatives() {
              doTest();
          }

          public void doTest() {
              flavorMap = (SystemFlavorMap)SystemFlavorMap.getDefaultFlavorMap();
              
              // Get all DataFlavors from the SystemFlavorMap
              vectorFlavors = new Vector(flavorMap.getFlavorsForNative(null));
              
              //Get the first DataFlavor to use as an example
              //
              DataFlavor element = (DataFlavor)vectorFlavors.firstElement();
              
              // Get all of the asssociated natives for this DataFlavor
              //
              vectorNatives1 = new Vector(flavorMap.getNativesForFlavor(element));
               
              System.out.println("\n\n**** Printing original set of mappings");
              printNativesForFlavor(vectorNatives1);
              
              flavorMap.addUnencodedNativeForFlavor(element, "TEST NATIVE");
              flavorMap.addUnencodedNativeForFlavor(element, "TEST NATIVE");
              flavorMap.addUnencodedNativeForFlavor(element, "TEST NATIVE");
              
              // Get assigned mappings from SystemFlavorMap
              vectorNatives2 = new Vector(flavorMap.getNativesForFlavor(element));
              
              System.out.println("\n\n**** Printing newly assigned mappings from SystemFlavorMap");
              printNativesForFlavor(vectorNatives2);
          }

          public void printNativesForFlavor(Vector vector) {
              String element;
              System.out.println("\n*** Printing all String Natives");
              System.out.println("*** Size = " + vector.size() + "\n");
              for (ListIterator i = vector.listIterator() ; i.hasNext() ;) {
                  element = (String)i.next();
                  System.out.println(element);
              }
          }

          public void printFlavorsForNative(Vector vector) {
              DataFlavor element;
              System.out.println("\n*** Printing all DataFlavors" +
                   "(mimeType and HumanPresentableName)");
              System.out.println("*** Size = " + vector.size() + "\n");
              for (ListIterator i = vector.listIterator() ; i.hasNext() ;) {
                  element = (DataFlavor)i.next();
                  System.out.println(element.getMimeType() + " NAME: " +
                    element.getHumanPresentableName());
              }
          }

          public static void main(String args[]) {
              new AddDuplicateNatives();
          }
      }

            dassunw Das Das (Inactive)
            rreynagasunw Rick Reynaga (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: