Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Location #698

Closed
mumbel opened this issue Jul 11, 2023 · 3 comments
Closed

Invalid Location #698

mumbel opened this issue Jul 11, 2023 · 3 comments
Milestone

Comments

@mumbel
Copy link

mumbel commented Jul 11, 2023

Invalid location
java.lang.IllegalArgumentException: Invalid location
	at java.desktop/javax.swing.text.JTextComponent.getSelectedText(JTextComponent.java:1784)
	at java.desktop/javax.swing.text.DefaultCaret.updateSystemSelection(DefaultCaret.java:1390)
	at java.desktop/javax.swing.text.DefaultCaret.focusGained(DefaultCaret.java:385)
	at com.formdev.flatlaf.ui.FlatCaret.focusGained(FlatCaret.java:150)
	at java.desktop/java.awt.AWTEventMulticaster.focusGained(AWTEventMulticaster.java:228)
	at java.desktop/java.awt.Component.processFocusEvent(Component.java:6515)
	at java.desktop/java.awt.Component.processEvent(Component.java:6382)
	at java.desktop/java.awt.Container.processEvent(Container.java:2266)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5001)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833)
	at java.desktop/java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1952)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:1061)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:687)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4882)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4833)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:773)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:97)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:746)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:744)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:743)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

Came across this clicking a window (I think, not 100% what triggered it) in Ghidra 10.3.1 (NationalSecurityAgency/ghidra#5539), which ships with FlatLaf 2.6, and using ubuntu 22.04 and JDK 17.0.7. Not sure if there's enough info to go off of, but figured worth reporting here too in case.

@DevCharly
Copy link
Collaborator

The exception is triggered when focusing a text component.
Can you remember what text component you clicked on or which was focused?
Is this reproducible?

DevCharly added a commit that referenced this issue Jul 17, 2023
…d location` if `JFormattedTextField.setDocument()` is invoked in a focus gained listener on that formatted text field. (issue #698)
@DevCharly
Copy link
Collaborator

Was able to reproduce such an exception.

Occurs only on Linux for JFormattedTextField if there is a focus gained listener that invokes JFormattedTextField.setDocument() on that text field.

Here is a test case. To reproduce

  1. start app on Linux
  2. press Tab key to move focus to formatted text field
  3. press Tab key to move focus to text field
  4. press Tab key to move focus again to formatted text field --> exception
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.text.PlainDocument;
import com.formdev.flatlaf.FlatLightLaf;

public class TestCaret
{
    public static void main( String[] args ) {
        SwingUtilities.invokeLater( () -> {
            FlatLightLaf.setup();

            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

            JFormattedTextField ftf = new JFormattedTextField();
            ftf.setText( "formatted text field" );
            ftf.setColumns( 30 );
            ftf.addFocusListener( new FocusAdapter() {
                @Override
                public void focusGained( FocusEvent e ) {
                    ftf.setDocument( new PlainDocument() );
                }
            } );

            Container contentPane = frame.getContentPane();
            contentPane.add( new JTextField( "text field" ), BorderLayout.NORTH );
            contentPane.add( ftf, BorderLayout.CENTER );

            frame.pack();
            frame.setLocationRelativeTo( null );
            frame.setVisible( true );
        } );
    }
}

@DevCharly
Copy link
Collaborator

Thanks for reporting 👍

fixed in latest 3.2-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

@DevCharly DevCharly added this to the 3.2 milestone Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants