Repository navigation
Fix drag and drop in java.awt.dnd - #57
Closed
duncanmcqueen wants to merge 3 commits into
Closed
duncanmcqueen wants to merge 3 commits into
duncanmcqueen wants to merge 3 commits into
Conversation
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
force-pushed
the
fix-dnd
branch
from
October 14, 2026 13:46
262dbb8 to
daed251
Compare
Contributor
Author
|
I split this pull request into one pull request for each fix:
The 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 I close this pull request, because the four new pull requests replace it. 🤖 Generated with Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 itsTransferable.DropTargetDragEventandDropTargetDropEventtest the source actions with~(actions ^ mask) != 0. This test is true for all values except~mask. Thus both constructors throwIllegalArgumentExceptionfor all valid actions.DropTargetContext.getCurrentDataFlavors()calls the peer but returnsnull.getTargetActions()returns a field that nothing sets, thusDropTargetDragEvent.getDropAction()is alwaysACTION_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-byline. If you need one, the owner will add it.🤖 Generated with Claude Code