Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8040322

TextArea.replaceRange() and insert() are broken with setText(null)

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7u45
    • Fix Version/s: 9
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b89
    • OS:
      windows_vista

      Backports

        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.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  arapte Ambarish Rapte
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  4 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: