JDK-4760507 : FlowView still calls setParent(null) during layout
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2002-10-09
  • Updated: 2002-10-18
  • Resolved: 2002-10-18
Related Reports
Duplicate :  
Description

Name: sv35042			Date: 10/09/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)


Linux simia 2.2.19 #20 Tue May 15 20:53:22 CEST 2001 i686
unknown
libc-2.1.3-141


A DESCRIPTION OF THE PROBLEM :
During row layout, FlowView still calls setParent(null); on
views that should not be discarded (but instead flown into
the next row). FlowView.adjustRow calls replace() on the
row, which will call setParent(null); on all Views that
should be moved into the next row.

It should not do so because then the View assumes it is not
used anymore and it has to do cleanup. This is a major
problem for ComponentView because the embedded component
will be temporarily removed, losing focus!

See related bug (which is fixed): 4522601

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the code.
2. Make sure (if necessary, depending on Font settings) by
typing into the text pane itself, that the embedded text
area is at/near the beginning of the second line.
3. Type a character into the text area.
4. It will lose focus, and the stack trace shows that
setParent(null); was invoked on the text area.

EXPECTED VERSUS ACTUAL BEHAVIOR :
FlowView should not temporarily disattach the ComponentView
because then the component will be removed and thus lose
focus.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
at java.lang.Thread.dumpStack(Thread.java:1071)
        at FlowBug$1.componentRemoved(FlowBug.java:25)
        at java.awt.Container.processContainerEvent(Container.java:1408)
        at java.awt.Container.processEvent(Container.java:1377)
        at java.awt.Component.dispatchEventImpl(Component.java:3526)
        at java.awt.Container.dispatchEventImpl(Container.java:1437)
        at java.awt.Component.dispatchEvent(Component.java:3367)
        at java.awt.Container.remove(Container.java:558)
        at java.awt.Container.remove(Container.java:584)
        at
javax.swing.text.ComponentView.setComponentParent(ComponentView.java:291)
        at javax.swing.text.ComponentView.setParent(ComponentView.java:235)
        at javax.swing.text.CompositeView.replace(CompositeView.java:173)
        at javax.swing.text.BoxView.replace(BoxView.java:164)
        at javax.swing.text.FlowView$FlowStrategy.adjustRow(FlowView.java:550)
        at javax.swing.text.FlowView$FlowStrategy.layoutRow(FlowView.java:490)
        at javax.swing.text.FlowView$FlowStrategy.layout(FlowView.java:397)
        at javax.swing.text.FlowView.layout(FlowView.java:182)
        at javax.swing.text.BoxView.setSize(BoxView.java:379)
        at javax.swing.text.BoxView.updateChildSizes(BoxView.java:348)
        at javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:330)
        at javax.swing.text.BoxView.layout(BoxView.java:682)
        at javax.swing.text.BoxView.setSize(BoxView.java:379)
        at
javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1528)
        at
javax.swing.plaf.basic.BasicTextUI.getPreferredSize(BasicTextUI.java:730)
        at javax.swing.JComponent.getPreferredSize(JComponent.java:1262)
        at javax.swing.JEditorPane.getPreferredSize(JEditorPane.java:1206)
        at
javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:767)
        at java.awt.Container.layout(Container.java:835)
        at java.awt.Container.doLayout(Container.java:825)
        at java.awt.Container.validateTree(Container.java:903)
        at
javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:347)
        at
javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:116)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:443)
        at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:190)
        at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:144)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)


This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import javax.swing.text.*;

import java.awt.*;
import java.awt.event.*;


public class FlowBug
{
    public static void main(String[] args)
    {
	JTextPane p = new JTextPane();

	p.setForeground(Color.blue);
	p.setText("ABC asda sd3112923 480 dskf vcnb  DEF GHJ");

	p.setCaretPosition(p.getDocument().getLength());

	p.insertComponent(new JTextArea("ABC"));

	p.addContainerListener(new ContainerAdapter()
	{
	    public void componentRemoved(ContainerEvent e)
	    {
		Thread.currentThread().dumpStack();
	    }
	});

	JFrame f = new JFrame();

	f.getContentPane().add(new JScrollPane(p));

	f.setSize(300, 300); f.show();
    }
}
---------- END SOURCE ----------
(Review ID: 146900) 
======================================================================