Skip to content

Fix drag and drop in java.awt.dnd - #57

Closed
duncanmcqueen wants to merge 3 commits into
ingelabs:masterfrom
duncanmcqueen:fix-dnd
Closed

duncanmcqueen wants to merge 3 commits into
ingelabs:masterfrom
duncanmcqueen:fix-dnd

Conversation

@duncanmcqueen

Copy link
Copy Markdown
Contributor

Summary

This pull request fixes three bugs in java.awt.dnd. Because of these bugs, drag and drop does not work with a toolkit that supplies drag and drop peers.

  • DragSource.startDrag() makes the drag source context peer and the context only one time. All later drags use the context of the first drag, with its Transferable.
  • DropTargetDragEvent and DropTargetDropEvent test the source actions with ~(actions ^ mask) != 0. This test is true for all values except ~mask. Thus both constructors throw IllegalArgumentException for all valid actions.
  • DropTargetContext.getCurrentDataFlavors() calls the peer but returns null. getTargetActions() returns a field that nothing sets, thus DropTargetDragEvent.getDropAction() is always ACTION_NONE. Now the context asks the peer, as in the JDK.

Tests

I found these bugs when I wrote an AWT toolkit for Haiku (see the related pull requests). With these changes, these drags work on Haiku with Kaffe: from Java to Java, from the Haiku file manager to Java (a file list), and from Java to a text editor. Each drag after the first one has the correct data.

I did not test on Linux. The changes are in Java code only and do not depend on the platform.

AI assistance

An AI model (Claude Code, by Anthropic) wrote these changes and this text. The repository owner directed the work. Please review the changes as you review other contributions.

The commits do not have a Signed-off-by line. If you need one, the owner will add it.

🤖 Generated with Claude Code

duncanmcqueen and others added 3 commits October 14, 2026 08:46
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 <noreply@anthropic.com>
Signed-off-by: duncanmcqueen <206344294+duncanmcqueen@users.noreply.github.com>
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 <noreply@anthropic.com>
Signed-off-by: duncanmcqueen <206344294+duncanmcqueen@users.noreply.github.com>
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 <noreply@anthropic.com>
Signed-off-by: duncanmcqueen <206344294+duncanmcqueen@users.noreply.github.com>
@duncanmcqueen

duncanmcqueen commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

I split this pull request into one pull request for each fix:

The DropTargetContext commit of this pull request had two fixes, so it is now two pull requests (#71 and #72). Together they have the same change.

Each pull request has a small test case and the results before and after the change. I reproduced all four problems on Linux with JamVM and the master branch, so they are not specific to Haiku.

I close this pull request, because the four new pull requests replace it.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant