From f15eeb34bcab93d358118d37356d04d6ea59b141 Mon Sep 17 00:00:00 2001 From: duncanmcqueen <206344294+duncanmcqueen@users.noreply.github.com> Date: Wed, 14 Oct 2026 08:26:59 -0500 Subject: [PATCH 1/3] DragSource: make a new drag context for each drag startDrag() made the drag source context peer and the context only when its fields were null, so every later drag reused the context of the first drag, with its trigger event and its Transferable. Make a new peer and a new context for each drag. Co-Authored-By: Claude Opus 5.5 Signed-off-by: duncanmcqueen <206344294+duncanmcqueen@users.noreply.github.com> --- java/awt/dnd/DragSource.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/java/awt/dnd/DragSource.java b/java/awt/dnd/DragSource.java index af8b376684..bd8d4133d9 100644 --- a/java/awt/dnd/DragSource.java +++ b/java/awt/dnd/DragSource.java @@ -144,15 +144,11 @@ public void startDrag(DragGestureEvent trigger, Cursor dragCursor, { flavorMap = map; - if (peer == null) - peer = Toolkit.getDefaultToolkit().createDragSourceContextPeer(trigger); - - if (context == null) - context = createDragSourceContext(peer, trigger, - dragCursor, - dragImage, - imageOffset, trans, - dsl); + // Each drag gets its own peer and context; reusing the first ones + // would drag the first Transferable again. + peer = Toolkit.getDefaultToolkit().createDragSourceContextPeer(trigger); + context = createDragSourceContext(peer, trigger, dragCursor, + dragImage, imageOffset, trans, dsl); if (peer == null) throw new InvalidDnDOperationException(); From 14a7184f793b645759455f43c32c7a16bbad9b64 Mon Sep 17 00:00:00 2001 From: duncanmcqueen <206344294+duncanmcqueen@users.noreply.github.com> Date: Wed, 14 Oct 2026 08:26:59 -0500 Subject: [PATCH 2/3] Accept valid source actions in drop target events DropTargetDragEvent and DropTargetDropEvent tested the source actions with ~(actions ^ mask) != 0. That test is true for every value except ~mask, so both constructors threw IllegalArgumentException for all valid actions, for example ACTION_COPY_OR_MOVE. Reject only bits that are not in the mask. Co-Authored-By: Claude Opus 5.5 Signed-off-by: duncanmcqueen <206344294+duncanmcqueen@users.noreply.github.com> --- java/awt/dnd/DropTargetDragEvent.java | 2 +- java/awt/dnd/DropTargetDropEvent.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/java/awt/dnd/DropTargetDragEvent.java b/java/awt/dnd/DropTargetDragEvent.java index 21c9e2b35c..db06c237d1 100644 --- a/java/awt/dnd/DropTargetDragEvent.java +++ b/java/awt/dnd/DropTargetDragEvent.java @@ -90,7 +90,7 @@ public DropTargetDragEvent (DropTargetContext context, Point location, | DnDConstants.ACTION_LINK | DnDConstants.ACTION_REFERENCE; - if (~(srcActions ^ srcActionsMask) != 0) + if ((srcActions & ~srcActionsMask) != 0) throw new IllegalArgumentException (); this.dropAction = dropAction; diff --git a/java/awt/dnd/DropTargetDropEvent.java b/java/awt/dnd/DropTargetDropEvent.java index 333f8c6cc5..9944ec9558 100644 --- a/java/awt/dnd/DropTargetDropEvent.java +++ b/java/awt/dnd/DropTargetDropEvent.java @@ -104,7 +104,7 @@ public DropTargetDropEvent(DropTargetContext dtc, Point location, | DnDConstants.ACTION_LINK | DnDConstants.ACTION_REFERENCE; - if (~(actions ^ actionsMask) != 0) + if ((actions & ~actionsMask) != 0) throw new IllegalArgumentException(); this.dropAction = dropAction; From daed2512118c81bcb23392523bfef2c8caa32982 Mon Sep 17 00:00:00 2001 From: duncanmcqueen <206344294+duncanmcqueen@users.noreply.github.com> Date: Wed, 14 Oct 2026 08:26:59 -0500 Subject: [PATCH 3/3] DropTargetContext: return the data flavors and the target actions getCurrentDataFlavors() called the peer but returned null, so drop targets could not see the offered flavors. getTargetActions() returned a field that nothing set, so DropTargetDragEvent.getDropAction() was always ACTION_NONE. Return the peer's flavors, and ask the peer for the target actions as the JDK does; without a peer, use the drop target's default actions. Co-Authored-By: Claude Opus 5.5 Signed-off-by: duncanmcqueen <206344294+duncanmcqueen@users.noreply.github.com> --- java/awt/dnd/DropTargetContext.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/java/awt/dnd/DropTargetContext.java b/java/awt/dnd/DropTargetContext.java index 4c21a6e8ad..e9a8cda91e 100644 --- a/java/awt/dnd/DropTargetContext.java +++ b/java/awt/dnd/DropTargetContext.java @@ -117,11 +117,18 @@ public void removeNotify() protected void setTargetActions(int actions) { targetActions = actions; + if (dtcp != null) + dtcp.setTargetActions(actions); } protected int getTargetActions() { - return targetActions; + // As in the JDK, the peer knows the actions; without one, use the + // drop target's default actions. + if (dtcp != null) + return dtcp.getTargetActions(); + return targetActions != 0 ? targetActions + : dropTarget.getDefaultActions(); } /** @@ -162,7 +169,7 @@ protected void rejectDrop () protected DataFlavor[] getCurrentDataFlavors () { if (dtcp != null) - dtcp.getTransferDataFlavors(); + return dtcp.getTransferDataFlavors(); return null; }