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

JOptionPane StackOverflow Error #969

Open
mrsaraira opened this issue Feb 12, 2025 · 3 comments
Open

JOptionPane StackOverflow Error #969

mrsaraira opened this issue Feb 12, 2025 · 3 comments

Comments

@mrsaraira
Copy link

mrsaraira commented Feb 12, 2025

I've encountered a StackOverflow error when showing a JOptionPane by passing a String to the message parameter of javax.swing.JOptionPane#showConfirmDialog(java.awt.Component, java.lang.Object, java.lang.String, int, int), which should wrap the message in a JLabel component internally.

Unfortunately, I don't have a snippet to help reproduce it; I have the stack trace.

P.S. I've managed to workaround the issue by passing JLabel to message parameter rather than passing a String.

Stack trace:

[AWT-EventQueue-0] ERROR my.app.Application - Uncaught exception occurred java.lang.StackOverflowError: null	
at java.base/java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:243)	
at java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:686)	
at java.base/java.lang.StringBuffer.append(StringBuffer.java:393)	
at java.base/java.io.StringWriter.write(StringWriter.java:122)	
at java.base/java.io.PrintWriter.implWrite(PrintWriter.java:621)	
at java.base/java.io.PrintWriter.write(PrintWriter.java:613)	
at java.base/java.io.PrintWriter.write(PrintWriter.java:635)	
at java.base/java.io.PrintWriter.print(PrintWriter.java:782)	
at java.base/java.io.PrintWriter.println(PrintWriter.java:1033)	
at java.base/java.lang.Throwable$WrappedPrintWriter.println(Throwable.java:801)	
at java.base/java.lang.Throwable.lockedPrintStackTrace(Throwable.java:684)	
at java.base/java.lang.Throwable.printStackTrace(Throwable.java:673)	
at java.base/java.lang.Throwable.printStackTrace(Throwable.java:749)	
at java.desktop/javax.swing.UIDefaults.getUI(UIDefaults.java:816)	
at java.desktop/javax.swing.UIManager.getUI(UIManager.java:1070)	
at java.desktop/javax.swing.JPanel.updateUI(JPanel.java:129)	
at java.desktop/javax.swing.JPanel.<init>(JPanel.java:89)	
at java.desktop/javax.swing.JPanel.<init>(JPanel.java:112)	
at java.desktop/javax.swing.JPanel.<init>(JPanel.java:120)	
at java.desktop/javax.swing.plaf.basic.BasicOptionPaneUI$1.<init>(BasicOptionPaneUI.java:486)	
at java.desktop/javax.swing.plaf.basic.BasicOptionPaneUI.addMessageComponents(BasicOptionPaneUI.java:486)	
at com.formdev.flatlaf.ui.FlatOptionPaneUI.addMessageComponents(FlatOptionPaneUI.java:220)	
at java.desktop/javax.swing.plaf.basic.BasicOptionPaneUI.addMessageComponents(BasicOptionPaneUI.java:512)	
at com.formdev.flatlaf.ui.FlatOptionPaneUI.addMessageComponents(FlatOptionPaneUI.java:220)	
at java.desktop/javax.swing.plaf.basic.BasicOptionPaneUI.addMessageComponents(BasicOptionPaneUI.java:512)	
at com.formdev.flatlaf.ui.FlatOptionPaneUI.addMessageComponents(FlatOptionPaneUI.java:220)	
at java.desktop/javax.swing.plaf.basic.BasicOptionPaneUI.addMessageComponents(BasicOptionPaneUI.java:512)
// recursive calls to the last two frames...

Java: 22.0.1 Oracle Corporation
OS: macOS 15.3 (24D60)

@DevCharly
Copy link
Collaborator

Hmm, works fine for me 😕

Probably it has something to do with the message string content.
Could you provide that string?
If you don't want to post it here, please send it to [email protected]

@mrsaraira
Copy link
Author

mrsaraira commented Feb 12, 2025

It's a really strange case because the strings are nothing special ex. "Exit Application".
I'll happily contribute the fix if I figure it out when this happens again.
This isn't a common issue for sure.

@DevCharly
Copy link
Collaborator

I think it has something to do with (larger?) multi-line message strings (that contain \n).

BasicOptionPaneUI.addMessageComponents() splits multi-line message and invokes itself with substrings...
But normally this does not result in stack overflow...

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