kamalchopra / jsyntaxpane

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

NPE when there is no parent assigned yet #75

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a new JEditorPane.
2. Don't assign a parent yet.
3. Call `pane.setContentType( "text/java" );`.

What is the expected output? What do you see instead?
Should work. But crashes with an NPE.

What version of the product are you using? On what operating system?
0.9.5b11

Please provide any additional information below.
Suggested patch:

Index: src/main/java/jsyntaxpane/components/LineNumbersRuler.java
===================================================================
--- src/main/java/jsyntaxpane/components/LineNumbersRuler.java  (revision 99)
+++ src/main/java/jsyntaxpane/components/LineNumbersRuler.java  (working copy)
@@ -103,7 +103,9 @@
         int w = d * charWidth + r_margin + l_margin;
         format = "%" + d + "d";
         setPreferredSize(new Dimension(w, h));
-        getParent().doLayout();
+        Container parent = getParent();
+        if (null != parent)
+            parent.doLayout();
     }

     /**

Original issue reported on code.google.com by peter.arrenbrecht on 12 Mar 2009 at 9:24

GoogleCodeExporter commented 9 years ago
This was reported before, and no easy way of solving it.  You MUST have the
JEditorPane enclosed in a JScrollBar before you call setContetType.  The above 
patch
caused some other issues.
If you do not want Line Numbers, then remove the component from the EdiorKit
configuration.

Original comment by ayman.al...@gmail.com on 12 Mar 2009 at 11:32

GoogleCodeExporter commented 9 years ago
Ah, thanks. I thought I had it removed, but only later realized my config was
outdated, too.

Original comment by peter.arrenbrecht on 12 Mar 2009 at 12:34

GoogleCodeExporter commented 9 years ago
Please add this patch or make sure you don't assume there is a parent. This bug 
causes 
issues in code you cannot alter, e.g. in a swing application that uses 
JEditorPane for 
syntax highlighting combined with e.g. JXErrorPane that uses JEditorPane as 
well. We 
cannot patch all other Java libraries to make sure they assign a parent before 
calling 
setContentType.

Original comment by rjako...@googlemail.com on 25 Dec 2009 at 11:29

GoogleCodeExporter commented 9 years ago
Did you try that patch?  I recall getting some other errors later, as stated in 
my
earlier comment.  

Original comment by ayman.al...@gmail.com on 28 Dec 2009 at 6:12

GoogleCodeExporter commented 9 years ago
Issue 140 has been merged into this issue.

Original comment by ayman.al...@gmail.com on 1 Apr 2010 at 4:53