Name: sdC67446 Date: 03/24/98
The specification for ctor
java.awt.dnd.DragSourceContext(DragSource,DragSourceContextPeer,
Component,int actions,Cursor,Image,Point,Transferable,DragSourceListener)
does not specify behavior for argument actions when
it is invalid. The current behavior is to throw IllegalArgumentException for
DnDConstants.ACTION_NONE and ignore other invalid values.
More acceptable behavior for all invalid actions here is to throw
IllegalArgumentException unless otherwise specified.
Here is what doc says:
--------------------------------------------------
public DragSourceContext(DragSource ds,
java.awt.dnd.peer.DragSourceContextPeer dscp,
Component c,
int a,
Cursor dragCursor,
Image dragImage,
Point offset,
Transferable t,
DragSourceListener dsl)
construct a DragSourceContext (called from DragSource)
Parameters:
ds - The DragSource that originated this operation
dscp - The DragSourceContextPeer for this operation
a - The operation(s)
dragCursor - The initial Cursor
dragImage - The image to drag (or null)
offset - The offset of the image origin from the hotspot
at the instant of the
triggering event
t - The Transferable
dsl - The DragSourceListener
Here is the test demonstrating the bug
-----------------Test.java------------------------
import java.awt.*;
import java.awt.image.*;
import java.awt.dnd.*;
import java.awt.dnd.peer.*;
import java.awt.datatransfer.*;
public class Test {
public static void main(String[] args) {
// valid actions
int actions[] = {
DnDConstants.ACTION_NONE,
DnDConstants.ACTION_COPY,
DnDConstants.ACTION_MOVE,
DnDConstants.ACTION_COPY_OR_MOVE,
DnDConstants.ACTION_LINK,
DnDConstants.ACTION_REFERENCE
};
DragSource ds = new DragSource();
DragSourceContextPeer dscp = new DragSourceContextPeer() {
public void startDrag(DragSourceContext ds, AWTEvent trigger,
Cursor cursor, int actions) {}
public Component getComponent() { return null; }
public void cancelDrag() {}
public Cursor getCursor() { return null; }
public void setCursor(Cursor c) {}
public AWTEvent getTrigger() {return null;}
};
Component component = new Button();
Cursor cursor = DragSource.DefaultCopyDrop;
Image image = new Image() {
public int getWidth(ImageObserver observer) {return 0;}
public int getHeight(ImageObserver observer){return 0;}
public ImageProducer getSource() {return null;}
public Graphics getGraphics() {return null;}
public void flush() {}
public Object getProperty(String name, ImageObserver observer) {
return null;
}
};
Point point = new Point(0,0);
Transferable transferable = new Transferable() {
public Object getTransferData(DataFlavor df) {
return null;
}
public DataFlavor[] getTransferDataFlavors() {
return null;
}
public boolean isDataFlavorSupported(DataFlavor df) {
return false;
}
};
DragSourceListener dsl = new DragSourceListener() {
public void dragEnter(DragSourceDragEvent dsde) {}
public void dragOver(DragSourceDragEvent dsde) {}
public void dropActionChanged(DragSourceDragEvent dsde) {}
public void dragExit(DragSourceEvent dsde) {}
public void dragDropEnd(DragSourceDropEvent dsde) {}
};
int act = 666;
// make sure act is unsupported
for (int i=0;i<actions.length;i++) {
if (act == actions[i]) {
System.out.println("oops!");
return;
}
}
DragSourceContext dsc = null;
try {
dsc = new DragSourceContext(ds,
dscp,
component,
act, // !!!
cursor,
image,
point,
transferable,
dsl
);
} catch (Exception e) {
System.out.println(e);
return;
}
System.out.println("No reaction.");
try {
dsc = new DragSourceContext(ds,
dscp,
component,
DnDConstants.ACTION_NONE, // !!!
cursor,
image,
point,
transferable,
dsl
);
} catch (Exception e) {
System.out.println("but here is "+e);
return;
}
System.out.println("No reaction too.");
}
}
---------Output from the test---------------------
No reaction.
but here is java.lang.IllegalArgumentException: actions == DnDConstants.ACTION_NONE
--------------------------------------------------
======================================================================