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

NPE in version 2.5 on Windows #600

Closed
ptorngren opened this issue Oct 14, 2022 · 5 comments
Closed

NPE in version 2.5 on Windows #600

ptorngren opened this issue Oct 14, 2022 · 5 comments
Milestone

Comments

@ptorngren
Copy link

After upgrading to FlatLaf 2.5, we get a NullPointerException when launching on Windows 10 and 11 (runs OK on macOS, and also on Windows in version 2.4).

Error is stable (happens every time during startup), but it is hard to pinpoint the cause and create a simple test class.

Stacktrace:
java.lang.NullPointerException: Cannot read field "preferred" because "this.xTotal" is null at java.desktop/javax.swing.BoxLayout.preferredLayoutSize(BoxLayout.java:294) at java.desktop/java.awt.Container.preferredSize(Container.java:1826) at java.desktop/java.awt.Container.getPreferredSize(Container.java:1810) at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1727) at java.desktop/java.awt.BorderLayout.preferredLayoutSize(BorderLayout.java:719) at java.desktop/java.awt.Container.preferredSize(Container.java:1826) at java.desktop/java.awt.Container.getPreferredSize(Container.java:1810) at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1727) at com.formdev.flatlaf.ui.FlatRootPaneUI$FlatRootLayout.layoutContainer(FlatRootPaneUI.java:444) at java.desktop/java.awt.Container.layout(Container.java:1541) at java.desktop/java.awt.Container.doLayout(Container.java:1530) at java.desktop/java.awt.Container.validateTree(Container.java:1725) at java.desktop/java.awt.Container.validateTree(Container.java:1734) at java.desktop/java.awt.Container.validate(Container.java:1660) at java.desktop/java.awt.Container.validateUnconditionally(Container.java:1697) at java.desktop/java.awt.Window.show(Window.java:1055) at java.desktop/java.awt.Component.show(Component.java:1728) at java.desktop/java.awt.Component.setVisible(Component.java:1675) at java.desktop/java.awt.Window.setVisible(Window.java:1036)

@DevCharly
Copy link
Collaborator

Not sure what change in 2.5 causes the issue. I'll have a look...

Could be a threading issue.
Do you invoke Window.setVisible() on the main thread?
Or on the AWT thread?

Make sure to use SwingUtilities.invokeLater()

Recommended way:

public static void main( String[] args ) {
    SwingUtilities.invokeLater( () -> {
        FlatLightLaf.setup();
        JFrame frame = ...
        ...
        frame.setVisible(true);
    } );
}

@ptorngren
Copy link
Author

We launch using SwingUtilities.invokeLater(), it's running on the AWT thread.

DevCharly added a commit that referenced this issue Oct 17, 2022
…u item does not have a parent (issue #600; regression since implementing #589 in FlatLaf 2.5; commit f6c5db0)
@DevCharly
Copy link
Collaborator

Found the problem, which was caused by a NPE in FlatMenuItemRenderer.getTopLevelFont() when using JideMenu.

Fixed in latest 2.6-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

Please give it a try.
If it fixes the issue in your app, I'll release FlatLaf 2.6 in a few days.

@DevCharly DevCharly added this to the 2.6 milestone Oct 17, 2022
@ptorngren
Copy link
Author

Yes, works fine!

@DevCharly
Copy link
Collaborator

Great.

FlatLaf 2.6 is now available 😄

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