-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0, 5.0, 6
-
b10
-
generic
-
generic
Name: agR10216 Date: 07/21/2003
In some places in Swing a reader (or stream) is requested on handling
a drop. The example is BacisTextUI.TextTransferHandler.importData()
and handleReaderImport(), where a reader is got via
DataFlavor.getReaderForText(), then the reader is completely read,
but it isn't closed. It should be closed as soon as possible to
release some native resources. Missing Reader.close() led to the
manifestation of the bug 4888520. There may be some other places in
Swing where close() should be called.
###@###.### 2003-07-21
======================================================================
Suggested fix from java.net member leouser:
A DESCRIPTION OF THE FIX :
BUG ID: 4893524 Swing drop targets should call close() on transferred readers and streams.
File: javax.swing.plaf.basic.BasicTextUI
JDK: jdk-6-rc-bin-b64-linux-i586-15_dec_2005.bin
This patch inserts a close() call and also removes multiple reasons for compiler warnings. There are still compiler warnings tossed but they stem from the TransferHandler and probably should be handled in their own patch.
Brian Harry
###@###.###
JAN 6, 2006
unified diff:
--- /home/nstuff/java6/jdk1.6.0/javax/swing/plaf/basic/BasicTextUI.java Thu Dec 15 02:17:45 2005
+++ /home/javarefs/javax/swing/plaf/basic/BasicTextUI.java Fri Jan 6 20:13:48 2006
@@ -433,16 +433,16 @@
EditorKit editorKit = getEditorKit(editor);
if ( editorKit != null
&& editorKit instanceof DefaultEditorKit) {
- Set storedForwardTraversalKeys = editor.
+ Set<AWTKeyStroke> storedForwardTraversalKeys = editor.
getFocusTraversalKeys(KeyboardFocusManager.
FORWARD_TRAVERSAL_KEYS);
- Set storedBackwardTraversalKeys = editor.
+ Set<AWTKeyStroke> storedBackwardTraversalKeys = editor.
getFocusTraversalKeys(KeyboardFocusManager.
BACKWARD_TRAVERSAL_KEYS);
- Set forwardTraversalKeys =
- new HashSet(storedForwardTraversalKeys);
- Set backwardTraversalKeys =
- new HashSet(storedBackwardTraversalKeys);
+ Set<AWTKeyStroke> forwardTraversalKeys =
+ new HashSet<AWTKeyStroke>(storedForwardTraversalKeys);
+ Set<AWTKeyStroke> backwardTraversalKeys =
+ new HashSet<AWTKeyStroke>(storedBackwardTraversalKeys);
if (editor.isEditable()) {
forwardTraversalKeys.
remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
@@ -1203,11 +1203,14 @@
return null;
}
- public static class BasicCaret extends DefaultCaret implements UIResource {}
+ public static class BasicCaret extends DefaultCaret implements UIResource {
+ static final long serialVersionUID = 3181078892434639970L;
+}
public static class BasicHighlighter extends DefaultHighlighter implements UIResource {}
static class BasicCursor extends Cursor implements UIResource {
+ static final long serialVersionUID = 7538198030475807811L;
BasicCursor(int type) {
super(type);
}
@@ -1929,7 +1932,7 @@
public void addLayoutComponent(Component comp, Object constraint) {
if (constraint instanceof View) {
if (constraints == null) {
- constraints = new Hashtable(7);
+ constraints = new Hashtable<Component,Object>(7);
}
constraints.put(comp, constraint);
}
@@ -1980,7 +1983,7 @@
* These are View objects for those components that are represented
* by a View in the View tree.
*/
- private Hashtable constraints;
+ private Hashtable<Component,Object> constraints;
private boolean i18nView = false;
}
@@ -1989,6 +1992,7 @@
* Wrapper for text actions to return isEnabled false in case editor is non editable
*/
class TextActionWrapper extends TextAction {
+ static final long serialVersionUID = 4395003531475678426L;
public TextActionWrapper(TextAction action) {
super((String)action.getValue(Action.NAME));
this.action = action;
@@ -2012,7 +2016,7 @@
* Registered in the ActionMap.
*/
class FocusAction extends AbstractAction {
-
+ static final long serialVersionUID = 324675851082230483L;
public void actionPerformed(ActionEvent e) {
editor.requestFocus();
}
@@ -2109,7 +2113,7 @@
}
static class TextTransferHandler extends TransferHandler implements UIResource {
-
+ static final long serialVersionUID = 1610021371057439349L;
private JTextComponent exportComp;
private boolean shouldRemove;
private int p0;
@@ -2377,7 +2381,7 @@
JTextComponent c = (JTextComponent)comp;
int pos = modeBetween
- ? ((JTextComponent.DropLocation)c.getDropLocation()).getIndex()
+ ? c.getDropLocation().getIndex()
: c.getCaretPosition();
// if we are importing to the same component that we exported from
@@ -2417,6 +2421,7 @@
}
handleReaderImport(r, c, useRead);
+ r.close();
if (isDrop) {
c.requestFocus();
@@ -2553,7 +2558,8 @@
} else if (Reader.class.equals(flavor.getRepresentationClass())) {
return new StringReader(richText);
} else if (InputStream.class.equals(flavor.getRepresentationClass())) {
- return new StringBufferInputStream(richText);
+ ByteArrayInputStream bais = new ByteArrayInputStream(richText.getBytes());
+ return new BufferedInputStream(bais);
}
throw new UnsupportedFlavorException(flavor);
}
JUnit TESTCASE :
Im uncertain what would be a good test to do here. All we are doing is ensuring that close gets called. We also clean up some compiler warnings... the compiler should be adequate for most of this. We do change a StringBufferInputStream to a ByteArrayInputStream put inside of a BufferedInputStream because the StringBufferInputStream is deprecated. If you feel that there is a test I could write, pass this back with your idea and I will try to write it.
FIX FOR BUG NUMBER:
4893524
In some places in Swing a reader (or stream) is requested on handling
a drop. The example is BacisTextUI.TextTransferHandler.importData()
and handleReaderImport(), where a reader is got via
DataFlavor.getReaderForText(), then the reader is completely read,
but it isn't closed. It should be closed as soon as possible to
release some native resources. Missing Reader.close() led to the
manifestation of the bug 4888520. There may be some other places in
Swing where close() should be called.
###@###.### 2003-07-21
======================================================================
Suggested fix from java.net member leouser:
A DESCRIPTION OF THE FIX :
BUG ID: 4893524 Swing drop targets should call close() on transferred readers and streams.
File: javax.swing.plaf.basic.BasicTextUI
JDK: jdk-6-rc-bin-b64-linux-i586-15_dec_2005.bin
This patch inserts a close() call and also removes multiple reasons for compiler warnings. There are still compiler warnings tossed but they stem from the TransferHandler and probably should be handled in their own patch.
Brian Harry
###@###.###
JAN 6, 2006
unified diff:
--- /home/nstuff/java6/jdk1.6.0/javax/swing/plaf/basic/BasicTextUI.java Thu Dec 15 02:17:45 2005
+++ /home/javarefs/javax/swing/plaf/basic/BasicTextUI.java Fri Jan 6 20:13:48 2006
@@ -433,16 +433,16 @@
EditorKit editorKit = getEditorKit(editor);
if ( editorKit != null
&& editorKit instanceof DefaultEditorKit) {
- Set storedForwardTraversalKeys = editor.
+ Set<AWTKeyStroke> storedForwardTraversalKeys = editor.
getFocusTraversalKeys(KeyboardFocusManager.
FORWARD_TRAVERSAL_KEYS);
- Set storedBackwardTraversalKeys = editor.
+ Set<AWTKeyStroke> storedBackwardTraversalKeys = editor.
getFocusTraversalKeys(KeyboardFocusManager.
BACKWARD_TRAVERSAL_KEYS);
- Set forwardTraversalKeys =
- new HashSet(storedForwardTraversalKeys);
- Set backwardTraversalKeys =
- new HashSet(storedBackwardTraversalKeys);
+ Set<AWTKeyStroke> forwardTraversalKeys =
+ new HashSet<AWTKeyStroke>(storedForwardTraversalKeys);
+ Set<AWTKeyStroke> backwardTraversalKeys =
+ new HashSet<AWTKeyStroke>(storedBackwardTraversalKeys);
if (editor.isEditable()) {
forwardTraversalKeys.
remove(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
@@ -1203,11 +1203,14 @@
return null;
}
- public static class BasicCaret extends DefaultCaret implements UIResource {}
+ public static class BasicCaret extends DefaultCaret implements UIResource {
+ static final long serialVersionUID = 3181078892434639970L;
+}
public static class BasicHighlighter extends DefaultHighlighter implements UIResource {}
static class BasicCursor extends Cursor implements UIResource {
+ static final long serialVersionUID = 7538198030475807811L;
BasicCursor(int type) {
super(type);
}
@@ -1929,7 +1932,7 @@
public void addLayoutComponent(Component comp, Object constraint) {
if (constraint instanceof View) {
if (constraints == null) {
- constraints = new Hashtable(7);
+ constraints = new Hashtable<Component,Object>(7);
}
constraints.put(comp, constraint);
}
@@ -1980,7 +1983,7 @@
* These are View objects for those components that are represented
* by a View in the View tree.
*/
- private Hashtable constraints;
+ private Hashtable<Component,Object> constraints;
private boolean i18nView = false;
}
@@ -1989,6 +1992,7 @@
* Wrapper for text actions to return isEnabled false in case editor is non editable
*/
class TextActionWrapper extends TextAction {
+ static final long serialVersionUID = 4395003531475678426L;
public TextActionWrapper(TextAction action) {
super((String)action.getValue(Action.NAME));
this.action = action;
@@ -2012,7 +2016,7 @@
* Registered in the ActionMap.
*/
class FocusAction extends AbstractAction {
-
+ static final long serialVersionUID = 324675851082230483L;
public void actionPerformed(ActionEvent e) {
editor.requestFocus();
}
@@ -2109,7 +2113,7 @@
}
static class TextTransferHandler extends TransferHandler implements UIResource {
-
+ static final long serialVersionUID = 1610021371057439349L;
private JTextComponent exportComp;
private boolean shouldRemove;
private int p0;
@@ -2377,7 +2381,7 @@
JTextComponent c = (JTextComponent)comp;
int pos = modeBetween
- ? ((JTextComponent.DropLocation)c.getDropLocation()).getIndex()
+ ? c.getDropLocation().getIndex()
: c.getCaretPosition();
// if we are importing to the same component that we exported from
@@ -2417,6 +2421,7 @@
}
handleReaderImport(r, c, useRead);
+ r.close();
if (isDrop) {
c.requestFocus();
@@ -2553,7 +2558,8 @@
} else if (Reader.class.equals(flavor.getRepresentationClass())) {
return new StringReader(richText);
} else if (InputStream.class.equals(flavor.getRepresentationClass())) {
- return new StringBufferInputStream(richText);
+ ByteArrayInputStream bais = new ByteArrayInputStream(richText.getBytes());
+ return new BufferedInputStream(bais);
}
throw new UnsupportedFlavorException(flavor);
}
JUnit TESTCASE :
Im uncertain what would be a good test to do here. All we are doing is ensuring that close gets called. We also clean up some compiler warnings... the compiler should be adequate for most of this. We do change a StringBufferInputStream to a ByteArrayInputStream put inside of a BufferedInputStream because the StringBufferInputStream is deprecated. If you feel that there is a test I could write, pass this back with your idea and I will try to write it.
FIX FOR BUG NUMBER:
4893524
- relates to
-
JDK-4888520 EXCEPTION_ACCESS_VIOLATION when closing application using _g build after using D
-
- Resolved
-