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

Random JProgressBar exceptions #830

Closed
Kokecena opened this issue Apr 1, 2024 · 5 comments
Closed

Random JProgressBar exceptions #830

Kokecena opened this issue Apr 1, 2024 · 5 comments

Comments

@Kokecena
Copy link

Kokecena commented Apr 1, 2024

Hello, I recently improved the SplashScreen of my application by injecting it in some parts of my application configurations, it rarely throws these 2 exceptions

Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException: Cannot read field “width” because “d” is null

or

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "javax.swing.JProgressBar.isIndeterminate()" because "this.progressBar" is null

At first I thought it was due to not running within the EDT but it still rarely throws the exception, at first I thought it was my implementation, but I tried without placing a flatlaf theme and the error from the more than 100 times I ran the program did not throw the error again

This is the only thing I do in some configurations,
image

and this is how I update the progress, Previously the code was only

SwingUtilities.invokeLater(()->{
    ...
    ...
});

and it kept throwing the same error

image

It doesn't really affect anything, it just throws that exception....

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "javax.swing.JProgressBar.isIndeterminate()" because "this.progressBar" is null
	at com.formdev.flatlaf.ui.FlatProgressBarUI.paint(FlatProgressBarUI.java:229)
	at com.formdev.flatlaf.ui.FlatProgressBarUI.update(FlatProgressBarUI.java:201)
	at java.desktop/javax.swing.JComponent.paintComponent(JComponent.java:842)
	at java.desktop/javax.swing.JComponent.paint(JComponent.java:1119)
	at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:952)
	at java.desktop/javax.swing.JComponent.paint(JComponent.java:1128)
	at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:952)
	at java.desktop/javax.swing.JComponent.paint(JComponent.java:1128)
	at java.desktop/javax.swing.JComponent.paintToOffscreen(JComponent.java:5311)
	at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBufferedFPScales(RepaintManager.java:1721)
	at java.desktop/javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1630)
	at java.desktop/javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1570)
	at java.desktop/javax.swing.RepaintManager.paint(RepaintManager.java:1337)
	at java.desktop/javax.swing.JComponent._paintImmediately(JComponent.java:5259)
	at java.desktop/javax.swing.JComponent.paintImmediately(JComponent.java:5069)
	at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:879)
	at java.desktop/javax.swing.RepaintManager$4.run(RepaintManager.java:862)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:862)
	at java.desktop/javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:835)
	at java.desktop/javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:784)
	at java.desktop/javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1898)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
	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.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:741)
	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)

I don't have the stack for the other error because it hasn't appeared, but a quick search on Google turned up this issue from another project saying that the error was from FlatLaf

I am using FlatLaf 3.4.1

OS

  • Windows 10
  • Windows 11

Java versions

  • Java 17 - Liberica
  • Java 17 - OpenJDK
@DevCharly
Copy link
Collaborator

I don't have the stack for the other error because it hasn't appeared, but a quick search on Google turned up this issue from another project saying that the error was from FlatLaf

Did you post the right link? I can not find any reference to FlatLaf on that page.

Looks like a threading issue.
At line 229 in FlatProgressBarUI.java it throws the NPE because "this.progressBar" is null:

A few lines before, "this.progressBar" is also used, but did not throw a NPE:

g.setColor( progressBar.getBackground() );

So the field was set to null in another thread.
Probably because BasicProgressBarUI.uninstallUI() was invoked.
This can occur e.g. if you destroy/dispose the progress bar not on EDT.
Or maybe if invoke use SwingUtilities.updateComponentTreeUI() or FlatLaf.updateUI() not on EDT.

I would recommend to set a breakpoint at BasicProgressBarUI.uninstallUI() to find out where "this.progressBar" is set to null.

DevCharly added a commit that referenced this issue May 9, 2024
…determinate progress bar UI or using `JProgressBar.setIndeterminate(false)` not on AWT thread, because this may throw NPE in `FlatProgressBarUI.paint()` (issues #841 and #830)
@DevCharly
Copy link
Collaborator

I've added some logs (including stack trace) to FlatProgressBarUI that warns when modifying indeterminate progress bar not on AWT thread.

Please try latest 3.5-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

@Kokecena
Copy link
Author

I had forgotten that I made this issue, an apology for not responding, the work had me busy haha, I will be doing tests

@Kokecena
Copy link
Author

Did you post the right link? I can not find any reference to FlatLaf on that page.

They make a small mention that it could come from FlatLaf, although I have never seen anything reported here, it is probably the typical threading issue.

image

@Kokecena
Copy link
Author

I've added some logs (including stack trace) to FlatProgressBarUI that warns when modifying indeterminate progress bar not on AWT thread.

Please try latest 3.5-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

I have already done the tests and I see that the log is thrown, I close the window within the EDT and at the moment the exception has not been thrown, anyway, thank you for the message telling me that I should run it in the EDT sometimes it jumps, but it is very very strange , weird swing stuff haha, I'll close this issue

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