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

REGRESSION: selectBestTextFlavor is broken

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • client-libs
    • beta
    • generic
    • generic

       ###@###.###

      DnD changes ported from ladybird introduced several regressions
      in DataFlavor.selectBestTextFlavor():

      1.DataFlavor.selectBestTextFlavor(null) returned null.
        Now it throws NullPointerException.
      2.DataFlavor.selectBestTextFlavor(new DataFlavor[0]) returned null.
        Now it throws NoSuchElementException.
      3.DataFlavor.selectBestTextFlavor() is documented to return a flavor
        in a supported encoding.
        Now it can return a flavor in an unsupported encoding.
        It is possible if the passed array contains a single text flavor
        in an unsupported encoding for example.
        
      Here is the test case to reproduce the problem:
      ====================================================================
      import java.awt.datatransfer.DataFlavor;

      public class Test {
          public static void main(String[] args) {
              try {
                  DataFlavor flavor = DataFlavor.selectBestTextFlavor(null);
                  System.out.println("best1=" + flavor);
              } catch (Throwable e) {
                  e.printStackTrace();
              }
              try {
                  DataFlavor flavor = DataFlavor.selectBestTextFlavor(new DataFlavor[0]);
                  System.out.println("best2=" + flavor);
              } catch (Throwable e) {
                  e.printStackTrace();
              }
              try {
                  DataFlavor flavor =
                      DataFlavor.selectBestTextFlavor(new DataFlavor[]
                                                      { new DataFlavor("text/plain; charset=unsupported; class=java.io.InputStream") });
                  System.out.println("best3=" + flavor);
              } catch (Throwable e) {
                  e.printStackTrace();
              }
          }
      }
      ==================================================================

      Here is the output indicating the buggy behavior
      in the current merlin workspace:
      ==================================================================
      java.lang.NullPointerException
              at java.util.Arrays$ArrayList.<init>(Arrays.java:2239)
              at java.util.Arrays.asList(Arrays.java:2225)
              at java.awt.datatransfer.DataFlavor.selectBestTextFlavor(DataFlavor.java:475)
              at Test.main(Test.java:6)
      java.util.NoSuchElementException
              at java.util.AbstractList$Itr.next(AbstractList.java:423)
              at java.util.Collections.max(Collections.java:646)
              at java.awt.datatransfer.DataFlavor.selectBestTextFlavor(DataFlavor.java:475)
              at Test.main(Test.java:12)
      best3=java.awt.datatransfer.DataFlavor[representationclass=java.io.InputStream;mimetype=text/plain]
      ==================================================================
      Here is the output produced by merlin build b39:
      ==================================================================
      best1=null
      best2=null
      best3=null
      ==================================================================

            dassunw Das Das (Inactive)
            son Oleg Sukhodolsky (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: