Repository navigation
DropTargetContext.getCurrentDataFlavors(): return the flavors - #71
Conversation
74e6f1c to
6740d42
Compare
|
Thanks, returning the peer’s result is the right fix. One minor thing. Without a peer, protected DataFlavor[] getCurrentDataFlavors ()
{
DataFlavor[] flavors = null;
if (dtcp != null)
flavors = dtcp.getTransferDataFlavors();
return flavors != null ? flavors : new DataFlavor[0];
}What do you think? |
getCurrentDataFlavors() called the peer but did not return its result, so it always returned null. Thus DropTargetDragEvent and DropTargetDropEvent did not show the offered data flavors, and isDataFlavorSupported() was always false. Return the peer's flavors. Without a peer, or if the peer returns null (as the GTK peer does), return an empty array, so that getCurrentDataFlavorsAsList() and isDataFlavorSupported() do not throw NullPointerException. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: duncanmcqueen <dwmcqueen@gmail.com>
6740d42 to
cde53cc
Compare
|
Thank you. I agree, and I used your code. Without a peer, or if the peer returns I added two cases to the test: no peer, and a peer that returns |
Split from #57.
Problem and fix
DropTargetContext.getCurrentDataFlavors()callsgetTransferDataFlavors()of the peer, but it does not return the result. It always returnsnull. ThusDropTargetDragEvent.getCurrentDataFlavors()andDropTargetDropEvent.getCurrentDataFlavors()returnnull, andisDataFlavorSupported()is always false.Now the method returns the flavors of the peer. Without a peer, or if the peer returns
null(the GTK peer does this, because itsgetTransferDataFlavors()is a stub), it returns an empty array. ThusgetCurrentDataFlavorsAsList()andisDataFlavorSupported()do not throwNullPointerException. I found this bug when I wrote an AWT toolkit for Haiku, which supplies drag and drop peers.How to reproduce
The methods are not public, so the test calls them with reflection. It tests the context without a peer, with a peer that returns
null(NullFlavorPeer), and with a peer that offers text (StubDropPeer).DropContextFlavors.javaStubDropPeer.javaNullFlavorPeer.javaResults
Haiku R1/beta6 x86_64 (hrev60228), JamVM with the Haiku port (#25 in ingelabs/jamvm), and ingelabs/classpath built on Haiku. I compiled each version of the changed classes with
javacfrom OpenJDK 8 and put them first on the boot class path (-Xbootclasspath/p). "Before" ismaster. "Previous" is the first version of this pull request. "After" is this version.The first version gave the "Previous" result for the stub peer also on Linux, and JDK 8 (1.8.0_504) also returns the string flavor. OpenJDK 27 on Linux returns an empty array without a peer.
Platforms
Not specific to Haiku. The problem is in
java.awt.dndand occurs with all toolkits. I reproduced it on Linux.AI assistance
An AI model (Claude Code, by Anthropic) wrote this change, the test and this text. The repository owner directed the work and checked the results. Please review it as you review other contributions.
🤖 Generated with Claude Code