JDK-8040322 : TextArea.replaceRange() and insert() are broken with setText(null)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u45
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_vista
  • Submitted: 2013-11-09
  • Updated: 2017-11-29
  • Resolved: 2015-09-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u152Fixed 9 b89Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6002]

A DESCRIPTION OF THE PROBLEM :
When text is placed in a TextArea with replaceRange() and insert(), this does not update the TextArea's "text" field with the text. Subsequently, when the TextArea is cleared with setText(null), it compares that the "text" field is empty, and so is the argument, and thus does not do anything. The text is not cleared from the TextArea, as it should be.

Apparently, the field "text" should be always kept in sync with the actual text in the TextArea, also in cases where replaceRange() and insert() is called.

Alternatively, the setText() should first get the actual text from the peer, before comparing to check if the TextArea contents are actually empty, and the text is being set to empty (in which case nothing needs to be done).

Currently, the TextArea erroneously thinks that it's still empty, when text has been added with replaceRange() and insert(), and the contents are set to empty with setText(null). This must be fixed.

REGRESSION.  Last worked in version 7u25

ADDITIONAL REGRESSION INFORMATION:
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) run javac TextAreaTest.java
2) run java TextAreaTest
3) Observe the TextArea in the window


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
TextArea is empty
ACTUAL -
TextArea still contains the text that was added via replaceRange() and insert()

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TextAreaTest
    extends Frame
{
    private TextArea textArea;

    private TextAreaTest()
    {
        super("Text area bug test");
        setSize(720, 540);

        addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent windowEvent)
            {
                setVisible(false);
                dispose();
                System.exit(0);
            }
        });

        setLayout(new BorderLayout());

        this.textArea = new TextArea();

        add(this.textArea, BorderLayout.SOUTH);

        setVisible(true);

        this.textArea.replaceRange("Some text", 0, 0);
        this.textArea.insert("Some more text, ", 0);
        this.textArea.setText(null);
    }

    public static void main(String[] args)
    {
        new TextAreaTest();
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
For example, TextArea.getText() resets the "text" field, making it work correctly.

However, this does not fix software that is already deployed.
Comments
Marked as 7-wnf as there are no immediate plans to fix for JDK 7. - If there's a customer bug filed we may revisit the 7-wnf - will not fix
11-10-2016

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

not a regression in 8 or 9
16-05-2014

The issue appears after the fix JDK-7184365 The real problem is that methods replaceRange(...) and insert(...) does not update the text variable if peer is not null or event is not sent during peer.replaceRange/insert methods call.
21-04-2014