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

Pasting text to a Java text input area using CTRL-V hangs application on Solaris

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1.6
    • CPU:
      generic, sparc
    • OS:
      solaris_2.4, solaris_2.5, solaris_2.5.1, solaris_2.6, solaris_9
    • Verification:
      Not verified

      Backports

        Description

        When using CTRL-V to paste text from the system clipboard that has been setup using the APIs from the Java Clipboard class to a Java text input area, the whole application hangs. If I use the "Copy" key on the Sun keyboard to setup the system clipboard then everything is working fine. By the way, the application doesn't hangs if I use the "Paste" key.

        To reproduce the bug:
        1. Compile the "CopyPasteBug" program using either JDK 1.1.1 or JDK 1.1.2
        2. Run the application
        3. Type a few words in the text area
        4. Select a word from the the text area and click on the "Copy" button
        5. Click on the "Paste" button, and notice that everything is working fine
        6. Press on the "Paste" key on the Sun keyboard, and it also works as expected
        7. Now press CTRL-V, and notice how the application hangs


        Source codes for CopyPasteBug.java:

        import java.awt.*;
        import java.awt.event.*;
        import java.io.*;
        import java.net.*;
        import java.awt.datatransfer.*;

        public class CopyPasteBug extends Frame
            implements ClipboardOwner, ActionListener
        {
            TextArea textArea;

            public CopyPasteBug()
            {
                setTitle( "CopyPasteBug" );

                textArea = new TextArea( 20, 40 );

                Button copybutton = new Button( "Copy" );
                copybutton.addActionListener( this );
                Button pastebutton = new Button( "Paste" );
                pastebutton.addActionListener( this );
                Button clearbutton = new Button( "Clear" );
                clearbutton.addActionListener( this );

                Panel panel = new Panel();
                panel.add( copybutton );
                panel.add( pastebutton );
                panel.add( clearbutton );

                add( "North", textArea );
                add( "South", panel );
            }

            public void actionPerformed( ActionEvent evt )
            {
                String cmd = evt.getActionCommand();

                if ( cmd.equals( "Copy" ) )
                {
                    String selection = textArea.getSelectedText();
                    if (selection != null)
                    {
                        StringSelection contents = new StringSelection(selection);
                        getToolkit().getSystemClipboard().setContents(contents, this);
                    }
                }
                else
                if ( cmd.equals( "Paste" ) )
                {
                    Transferable contents =
                        getToolkit().getSystemClipboard().getContents( this );

                    if ( contents != null )
                    {
                        try
                        {
                            String selection = (String)contents.getTransferData(
                                DataFlavor.stringFlavor );
                            if (selection != null)
                                textArea.insert(selection, textArea.getCaretPosition());
                        }
                        catch ( Exception e )
                        {
                            textArea.setText( "Error pasting:\n" + e.toString() );
                        }
                    }
                }
                else
                if ( cmd.equals( "Clear" ) )
                {
                    textArea.setText("");
                }
            }

            public void lostOwnership(Clipboard clipboard, Transferable contents)
            {
            }

            public static void main( String[] args )
            {
                Frame f = new CopyPasteBug();
                f.pack();
                f.show();
            }
        }

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                xdengsunw Xianfa Deng (Inactive)
                Reporter:
                duke J. Duke (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: