tuliob / jsyntaxpane

Automatically exported from code.google.com/p/jsyntaxpane
0 stars 0 forks source link

ClassCastException on application start #53

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I get it if JEditorPane is placed inside JSplitPane. I was trying to change
the code in several way but without any result.

It looks like this happen only if I'm trying to show it on application
start. If I open different component and then one with jsyntaxpane it all
works fine.

I will be glad for any suggestions.

Here is exception:

java.lang.ClassCastException: javax.swing.text.PlainDocument cannot be cast
to jsyntaxpane.SyntaxDocument
    at jsyntaxpane.SyntaxView.drawUnselectedText(SyntaxView.java:75)
    at javax.swing.text.PlainView.drawElement(PlainView.java:96)
    at javax.swing.text.PlainView.drawLine(PlainView.java:65)
    at javax.swing.text.PlainView.paint(PlainView.java:288)
    at javax.swing.plaf.basic.BasicTextUI$RootView.paint(BasicTextUI.java:1422)
    at javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:722)
    at javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:869)
    at javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:848)
    at javax.swing.JComponent.paintComponent(JComponent.java:763)
    at javax.swing.JComponent.paint(JComponent.java:1027)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JViewport.paint(JViewport.java:747)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JSplitPane.paintChildren(JSplitPane.java:1030)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JComponent.paintChildren(JComponent.java:864)
    at javax.swing.JComponent.paint(JComponent.java:1036)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5122)
    at
javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:277
)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1217)
    at javax.swing.JComponent._paintImmediately(JComponent.java:5070)
    at javax.swing.JComponent.paintImmediately(JComponent.java:4880)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:803)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
    at
javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueU
tilities.java:128)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
    at
java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269
)
    at
java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174
)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Original issue reported on code.google.com by arek.str...@gmail.com on 20 Jan 2009 at 5:35

GoogleCodeExporter commented 9 years ago
Are you sure initKit is being called?  Can you post sample code for me to 
reproduce
the issue?  Just one java class without dependencies please.

Original comment by ayman.al...@gmail.com on 20 Jan 2009 at 6:52

GoogleCodeExporter commented 9 years ago
Writing something similar in separate class was not very successful. I cannot 
get
exception with very simple test code... 

To me it suggest what the fact what few hundred over classes are initialize at 
a same
time make a difference. Also in real application this is not happening all the 
time,
maybe only 50-60%.

If DefaultSyntaxKit.initKit() will not be called I believe the stack-trace will 
not
show first line. Everything will work fine, just without any syntax support.

I will still play with it in evening, and I will let you know if I find 
something more.

Original comment by arek.str...@gmail.com on 21 Jan 2009 at 2:55

GoogleCodeExporter commented 9 years ago
Placing the setting of ContentType into invokeLater() somehow fixed the problem.
I have something like this now:
    SwingUtilities.invokeLater(new Runnable()
    {
        public void run()
        {
            editor.setContentType("text/groovy");
            editor.setText(s);
        }
    });      

I also removed doLayout() as javadoc says clearly to not call it from user 
code. I
don't see difference in behavior now with or without it (before using 
invokeLater() I
believe if was freezing whole application sometimes - but maybe because I was 
trying
so many things it was something else).

I believe you run (or it is run by swing) some initialization code inside
invokeLater(). When application starts, this code is scheduled to run later 
(after
all swing classes are build etc.). When I set ContentType before calling 
setText(),
your SyntaxView expect perfect situation when all was already initialized and 
throws
ClassCastException.
This is not visible in simple one frame, one panel application as there is time 
to do
it all. It is problem only in more complex applications.

I'm not sure if placing whole setting inside invokeLater() is a fix or it is
workaround, but I believe you should make users aware of this problem.

Original comment by arek.str...@gmail.com on 22 Jan 2009 at 3:18

GoogleCodeExporter commented 9 years ago
Actually you should use invokeLater to show the very first Swing window / 
Frame. 
Have a look at the SyntaxTester main method. 
I will close the issue.  Thanks for the report.

Original comment by ayman.al...@gmail.com on 22 Jan 2009 at 6:21