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

The Toolkit.createCustomCursor does not check absence of the image of cursor

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      kestrel
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description



      Name: akC57697 Date: 02/18/99



       The Toolkit.createCustomCursor does not check absence of the image of cursor.

       The javadoc says:
      "
      public Cursor createCustomCursor(Image cursor,
                                       Point hotSpot,
                                       String name)
                                throws IndexOutOfBoundsException

            Creates a new custom cursor object.
            Parameters:
                  image - the image to display when the cursor is active.
                  hotSpot - the X and Y of the large cursor's hot spot. The hotSpot values
                  must be less than the Dimension returned by getBestCursorSize().
                  name - a localized description of the cursor, for Java Accessibility use.
            Throws:
                  IndexOutOfBoundsException - if the hotSpot values are outside the bounds
                  of the cursor.
      "

      ---------------------------------------8-<-----------------------------------
      import java.awt.Toolkit;
      import java.awt.Dimension;
      import java.awt.Point;
      import java.awt.Cursor;
      import java.awt.Image;
      import java.awt.Canvas;


      public class Test {

          public static void main(String argv[]) {
              Toolkit tk = Toolkit.getDefaultToolkit();
              Dimension dk = tk.getBestCursorSize(16, 16);
              Image image = tk.getImage("NON_EXISTING_FILE.gif");
              if (image == null) {
                  System.out.println("No image has loaded");
                  System.exit(0);
              }
              Cursor c = null;
              Canvas cp = new Canvas();
              Point p = new Point(0, 0);
              try {
                  c = tk.createCustomCursor(image, p, "Test");
              } catch (Exception e) {
                  System.out.println("image:" + image + " with the size: "
                          + image.getWidth(cp) + " x " + image.getHeight(cp));
                  System.out.println("1 getBestCursorSize:" + dk);
                  System.out.println("Values are:" + p);
                  System.out.println("The cursor size is " + dk);
                  System.out.println("Unexpected " + e);
                  e.printStackTrace();
                  System.exit(0);
              }
              System.out.println("OKAY");
              System.exit(0);
          }
      }
      ---------------------------------------8-<-----------------------------------
      (No JIT to see the trace)
      image:sun.awt.motif.X11Image@7f3eb146 with the size: -1 x -1
      1 getBestCursorSize:java.awt.Dimension[width=16,height=16]
      Values are:java.awt.Point[x=0,y=0]
      The cursor size is java.awt.Dimension[width=16,height=16]
      Unexpected java.lang.NegativeArraySizeException
      java.lang.NegativeArraySizeException
      at sun.awt.CustomCursor.<init>(CustomCursor.java:69)
      at sun.awt.motif.X11CustomCursor.<init>(X11CustomCursor.java:45)
      at sun.awt.motif.MToolkit.createCustomCursor(MToolkit.java:377)
      at Test.main(Test.java:23)

      java full version "JDK-1.2.2-E"

      -----------------------------------------------------------------
       * @(#)CustomCursor.java 1.7 99/01/11
      ...
      line 38 MediaTracker tracker = new MediaTracker(c);
              tracker.addImage(cursor, 0);
              try {
                  tracker.waitForAll();
              } catch (InterruptedException e) {
              } <--tracker.isErrorAny()? would catch this
              int width = cursor.getWidth(c);
              int height = cursor.getHeight(c);
      ...


      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              tdv Dmitri Trembovetski (Inactive)
              Reporter:
              akuzminorcl Alexander Kuzmin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: