-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.4.2_03
-
None
-
sparc
-
solaris_1
Seems to be a regression bug in GlyphView 1.4.2_03-b02 where if you set the highlighter to null in a TextComponent and set the color attribute of the text, it will throw the following NullPointerException when trying to render the text. Sample code that throws this NPE follows the stacktrace.
java.lang.NullPointerException
at javax.swing.text.GlyphView.paint(GlyphView.java:367)
at javax.swing.text.BoxView.paintChild(BoxView.java:144)
at javax.swing.text.BoxView.paint(BoxView.java:407)
at javax.swing.text.BoxView.paintChild(BoxView.java:144)
at javax.swing.text.BoxView.paint(BoxView.java:407)
at javax.swing.text.ParagraphView.paint(ParagraphView.java:569)
at javax.swing.text.BoxView.paintChild(BoxView.java:144)
at javax.swing.text.BoxView.paint(BoxView.java:407)
at javax.swing.plaf.basic.BasicTextUI$RootView.paint(BasicTextUI.java:1319)
at javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:636)
at javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:770)
at javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:749)
at javax.swing.JComponent.paintComponent(JComponent.java:541)
at javax.swing.JComponent.paint(JComponent.java:808)
at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4787)
at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4740)
at javax.swing.JComponent._paintImmediately(JComponent.java:4685)
at javax.swing.JComponent.paintImmediately(JComponent.java:4488)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:117)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
--------- Test code -----------
The following throws NPE when run using 1.4.2_03-b02
Comment out one of the lines 'text.setHighlighter(null); ' or 'StyleConstants.setForeground(attrs, Color.blue);' and it will execute correctly.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class HighlighterTest extends JPanel {
public static void main(String [] parms) {
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
JTextComponent text = new JTextPane();
// highlighter disabled
try {
SimpleAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setForeground(attrs, Color.blue);
text.getDocument().insertString(0, "This is a test", attrs);
} catch (Exception ex) {
ex.printStackTrace();
System.exit(10);
}
Container cont = frame.getContentPane();
cont.setLayout(new BorderLayout());
cont.add(text, BorderLayout.CENTER);
frame.pack();
frame.show();
}
}
java.lang.NullPointerException
at javax.swing.text.GlyphView.paint(GlyphView.java:367)
at javax.swing.text.BoxView.paintChild(BoxView.java:144)
at javax.swing.text.BoxView.paint(BoxView.java:407)
at javax.swing.text.BoxView.paintChild(BoxView.java:144)
at javax.swing.text.BoxView.paint(BoxView.java:407)
at javax.swing.text.ParagraphView.paint(ParagraphView.java:569)
at javax.swing.text.BoxView.paintChild(BoxView.java:144)
at javax.swing.text.BoxView.paint(BoxView.java:407)
at javax.swing.plaf.basic.BasicTextUI$RootView.paint(BasicTextUI.java:1319)
at javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:636)
at javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:770)
at javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:749)
at javax.swing.JComponent.paintComponent(JComponent.java:541)
at javax.swing.JComponent.paint(JComponent.java:808)
at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4787)
at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4740)
at javax.swing.JComponent._paintImmediately(JComponent.java:4685)
at javax.swing.JComponent.paintImmediately(JComponent.java:4488)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:117)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
--------- Test code -----------
The following throws NPE when run using 1.4.2_03-b02
Comment out one of the lines 'text.setHighlighter(null); ' or 'StyleConstants.setForeground(attrs, Color.blue);' and it will execute correctly.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class HighlighterTest extends JPanel {
public static void main(String [] parms) {
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
JTextComponent text = new JTextPane();
// highlighter disabled
try {
SimpleAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setForeground(attrs, Color.blue);
text.getDocument().insertString(0, "This is a test", attrs);
} catch (Exception ex) {
ex.printStackTrace();
System.exit(10);
}
Container cont = frame.getContentPane();
cont.setLayout(new BorderLayout());
cont.add(text, BorderLayout.CENTER);
frame.pack();
frame.show();
}
}
- duplicates
-
JDK-4532590 JTextPane jTextPane.setHighlighter(null) doesn't disable highlighter.
-
- Resolved
-