-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
6u10
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.6.0_10-ea"
Java(TM) SE Runtime Environment (build 1.6.0_10-ea-b09)
Java HotSpot(TM) Client VM (build 11.0-b09, mixed mode, sharing)
The compiler is: javac 1.6.0_03
FULL OS VERSION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The gui thread invokes component's importData(), which invokes Transferable's getTransferData(). I do not see the debug trace right after the transferable invocation. I conclude that the thread terminates. But no exception stack traces are printed in the console.
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Did not try
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See source code below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Drag and Drop produces the following messages:
DEBUG1: dropping on 'Sample i'
DEBUG2: getTransferData(): The item to drop is 'Sample j'
The third message expected:
DEBUG3: got 'Sampe j'
is not shown.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Use console to compile and run:
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.filechooser.*;
import java.io.*;
import java.util.*;
import java.awt.datatransfer.*;
class SongTree extends JTree {
class Item extends DefaultMutableTreeNode {
Item(Object userObj) {
super(userObj);
}
void appendChild(Item item) {
((DefaultTreeModel)treeModel).insertNodeInto(item, this, getChildCount());
}
public void Drop(Object o) {
log("Some " + o + "-thing has dropped on me. Handling is not implemented.");
}
}
static void log(String msg) {
System.out.println(msg);
}
SongTree() {
super();
Item top = new Item("root");
setModel(new DefaultTreeModel(top));
top.appendChild(new Item("Sample 1"));
top.appendChild(new Item("Sample 2"));
getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
setEditable(true);
setRootVisible(true);
setDragEnabled(true);
setDropMode(DropMode.ON_OR_INSERT);
expandRow(0);
setTransferHandler(new TransferHandler() {
public boolean importData(TransferSupport support) {
if (!canImport(support)) {
return false;
}
try {
Item target = (Item)((JTree.DropLocation)support.getDropLocation()).getPath().getLastPathComponent();
log("dropping on " + target + " DEBUG1"); // <- I SEE THIS
Object o = support.getTransferable().getTransferData(null);
log("dropping item " + o + " DEBUG3"); // <-- BUT CANNOT SEE THIS!!
target.Drop(o);
log("ok");
} catch (UnsupportedFlavorException e) {
log("ERROR " + e + " importing the data");
return false;
} catch (IOException e) {
log("ERROR " + e + " importing the data");
return false;
}
log("ok2");
return true;
}
public boolean canImport(TransferSupport support) {
JTree.DropLocation dropLocation = (JTree.DropLocation)support.getDropLocation();
if (!support.isDrop() || dropLocation.getPath() == null) {
return false;
}
Class transferrableRefClass = support.getDataFlavors()[0].getRepresentationClass();
log("ref is " + transferrableRefClass);
return true;//((Item) dropLocation.getPath().getLastPathComponent()).isMethodImplemented("Drop", new Class[] {transferrableRefClass});
}
public int getSourceActions(JComponent comp) {
log("getSourceActions");
return LINK; // COPY
}
public Transferable createTransferable(JComponent comp) {
final Object ref = getSelectionPath().getLastPathComponent();
log("createTransferable(" + (ref) + ")");
return new Transferable() {
final DataFlavor[] flavours = new DataFlavor[] {new DataFlavor(ref.getClass(), DataFlavor.javaJVMLocalObjectMimeType)};
public Object getTransferData(DataFlavor flavor) {
log("getTransferData. The item to drop is " + ref + " DEBUG2"); // <- I SEE THIS
return ref;
}
public DataFlavor[] getTransferDataFlavors() {log("getFlavours"); return flavours;}
public boolean isDataFlavorSupported (DataFlavor flavor) {
log("isFlavourSupported(" + flavor + ")");
return false; // this normally must not be called
}
};
}
});
} // TransferHandler
}
class JTreeTest {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
final JFrame frame = new JFrame("JTreeTest");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new SongTree(), BorderLayout.CENTER);
frame.setPreferredSize(new Dimension(300, 300));
frame.pack();
frame.setVisible(true);
}
});
}
---------- END SOURCE ----------
java version "1.6.0_10-ea"
Java(TM) SE Runtime Environment (build 1.6.0_10-ea-b09)
Java HotSpot(TM) Client VM (build 11.0-b09, mixed mode, sharing)
The compiler is: javac 1.6.0_03
FULL OS VERSION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The gui thread invokes component's importData(), which invokes Transferable's getTransferData(). I do not see the debug trace right after the transferable invocation. I conclude that the thread terminates. But no exception stack traces are printed in the console.
THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes
THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Did not try
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See source code below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Drag and Drop produces the following messages:
DEBUG1: dropping on 'Sample i'
DEBUG2: getTransferData(): The item to drop is 'Sample j'
The third message expected:
DEBUG3: got 'Sampe j'
is not shown.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
Use console to compile and run:
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.filechooser.*;
import java.io.*;
import java.util.*;
import java.awt.datatransfer.*;
class SongTree extends JTree {
class Item extends DefaultMutableTreeNode {
Item(Object userObj) {
super(userObj);
}
void appendChild(Item item) {
((DefaultTreeModel)treeModel).insertNodeInto(item, this, getChildCount());
}
public void Drop(Object o) {
log("Some " + o + "-thing has dropped on me. Handling is not implemented.");
}
}
static void log(String msg) {
System.out.println(msg);
}
SongTree() {
super();
Item top = new Item("root");
setModel(new DefaultTreeModel(top));
top.appendChild(new Item("Sample 1"));
top.appendChild(new Item("Sample 2"));
getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
setEditable(true);
setRootVisible(true);
setDragEnabled(true);
setDropMode(DropMode.ON_OR_INSERT);
expandRow(0);
setTransferHandler(new TransferHandler() {
public boolean importData(TransferSupport support) {
if (!canImport(support)) {
return false;
}
try {
Item target = (Item)((JTree.DropLocation)support.getDropLocation()).getPath().getLastPathComponent();
log("dropping on " + target + " DEBUG1"); // <- I SEE THIS
Object o = support.getTransferable().getTransferData(null);
log("dropping item " + o + " DEBUG3"); // <-- BUT CANNOT SEE THIS!!
target.Drop(o);
log("ok");
} catch (UnsupportedFlavorException e) {
log("ERROR " + e + " importing the data");
return false;
} catch (IOException e) {
log("ERROR " + e + " importing the data");
return false;
}
log("ok2");
return true;
}
public boolean canImport(TransferSupport support) {
JTree.DropLocation dropLocation = (JTree.DropLocation)support.getDropLocation();
if (!support.isDrop() || dropLocation.getPath() == null) {
return false;
}
Class transferrableRefClass = support.getDataFlavors()[0].getRepresentationClass();
log("ref is " + transferrableRefClass);
return true;//((Item) dropLocation.getPath().getLastPathComponent()).isMethodImplemented("Drop", new Class[] {transferrableRefClass});
}
public int getSourceActions(JComponent comp) {
log("getSourceActions");
return LINK; // COPY
}
public Transferable createTransferable(JComponent comp) {
final Object ref = getSelectionPath().getLastPathComponent();
log("createTransferable(" + (ref) + ")");
return new Transferable() {
final DataFlavor[] flavours = new DataFlavor[] {new DataFlavor(ref.getClass(), DataFlavor.javaJVMLocalObjectMimeType)};
public Object getTransferData(DataFlavor flavor) {
log("getTransferData. The item to drop is " + ref + " DEBUG2"); // <- I SEE THIS
return ref;
}
public DataFlavor[] getTransferDataFlavors() {log("getFlavours"); return flavours;}
public boolean isDataFlavorSupported (DataFlavor flavor) {
log("isFlavourSupported(" + flavor + ")");
return false; // this normally must not be called
}
};
}
});
} // TransferHandler
}
class JTreeTest {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
final JFrame frame = new JFrame("JTreeTest");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new SongTree(), BorderLayout.CENTER);
frame.setPreferredSize(new Dimension(300, 300));
frame.pack();
frame.setVisible(true);
}
});
}
---------- END SOURCE ----------