-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
6u10
-
Cause Known
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Adding a style sheet rule to a JTextPane causes Nimbus to throw a NullPointerException, the same code works with Metal and Windows Xp look and feels.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test code provided
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A dialog should be shown where the font in the JTextPane has been changed with a style sheet rule.
ACTUAL -
NullPointerException
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicEditorPaneUI.updateCSS(BasicEditorPaneUI.java:301)
at javax.swing.plaf.basic.BasicEditorPaneUI.updateDisplayProperties(BasicEditorPaneUI.java:223)
at javax.swing.plaf.basic.BasicEditorPaneUI.propertyChange(BasicEditorPaneUI.java:163)
at javax.swing.plaf.synth.SynthEditorPaneUI.propertyChange(SynthEditorPaneUI.java:90)
at javax.swing.plaf.synth.SynthTextPaneUI.propertyChange(SynthTextPaneUI.java:73)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.propertyChange(BasicTextUI.java:1794)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276)
at java.awt.Component.firePropertyChange(Component.java:8128)
at java.awt.Component.setFont(Component.java:1793)
at java.awt.Container.setFont(Container.java:1554)
at javax.swing.JComponent.setFont(JComponent.java:2723)
at nimbuscss.Main.show(Main.java:65)
at nimbuscss.Main.main(Main.java:90)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/*
* Nimbus causes java.lang.NullPointerException
* at javax.swing.plaf.basic.BasicEditorPaneUI.updateCSS(BasicEditorPaneUI.java:301)
*/
package nimbuscss;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.Window;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument;
/**
*
* @author scott.palmer
*/
public class Main {
public Main() throws Exception {
// Change to FALSE to see that this code works on Windows LnF (or Metal)
if (true) {
for (UIManager.LookAndFeelInfo lnfi : UIManager.getInstalledLookAndFeels()) {
if (lnfi.getName().contains("Nimbus")) {
UIManager.setLookAndFeel(lnfi.getClassName());
break;
}
}
} else {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
}
public void show(Window parent) {
JTextPane pane = new JTextPane();
pane.setOpaque(false);
pane.setContentType("text/html");
pane.setEditable(false);
pane.setText("<html>Test <a href=\"http://java.sun.com/\">java.sun.com</a>.</html>");
//"<html>Test <a href=\"http://www.digital-rapids.com/\">www.digital-rapids.com</a>.</html>");
System.out.println("document is a "+pane.getDocument().getClass().getName());
if (pane.getDocument() instanceof HTMLDocument) {
HTMLDocument htmlDoc = (HTMLDocument) pane.getDocument();
htmlDoc.getStyleSheet().addRule("body {font-family: Arial;}");
}
pane.setFont(Font.getFont(Font.SANS_SERIF));
pane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
System.out.println("hyperlinkUpdate "+e.getEventType());
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
URI target = e.getURL().toURI();
Desktop.getDesktop().browse(target);
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
JOptionPane.showMessageDialog(
parent,
pane,
"Fails with Nimbus",
JOptionPane.ERROR_MESSAGE);
}
public static void main(String [] args) throws Exception {
new Main().show(null);
System.exit(0);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't use Nimbus
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) Client VM (build 14.0-b16, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Adding a style sheet rule to a JTextPane causes Nimbus to throw a NullPointerException, the same code works with Metal and Windows Xp look and feels.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test code provided
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A dialog should be shown where the font in the JTextPane has been changed with a style sheet rule.
ACTUAL -
NullPointerException
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicEditorPaneUI.updateCSS(BasicEditorPaneUI.java:301)
at javax.swing.plaf.basic.BasicEditorPaneUI.updateDisplayProperties(BasicEditorPaneUI.java:223)
at javax.swing.plaf.basic.BasicEditorPaneUI.propertyChange(BasicEditorPaneUI.java:163)
at javax.swing.plaf.synth.SynthEditorPaneUI.propertyChange(SynthEditorPaneUI.java:90)
at javax.swing.plaf.synth.SynthTextPaneUI.propertyChange(SynthTextPaneUI.java:73)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.propertyChange(BasicTextUI.java:1794)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276)
at java.awt.Component.firePropertyChange(Component.java:8128)
at java.awt.Component.setFont(Component.java:1793)
at java.awt.Container.setFont(Container.java:1554)
at javax.swing.JComponent.setFont(JComponent.java:2723)
at nimbuscss.Main.show(Main.java:65)
at nimbuscss.Main.main(Main.java:90)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
/*
* Nimbus causes java.lang.NullPointerException
* at javax.swing.plaf.basic.BasicEditorPaneUI.updateCSS(BasicEditorPaneUI.java:301)
*/
package nimbuscss;
import java.awt.Desktop;
import java.awt.Font;
import java.awt.Window;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTextPane;
import javax.swing.UIManager;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument;
/**
*
* @author scott.palmer
*/
public class Main {
public Main() throws Exception {
// Change to FALSE to see that this code works on Windows LnF (or Metal)
if (true) {
for (UIManager.LookAndFeelInfo lnfi : UIManager.getInstalledLookAndFeels()) {
if (lnfi.getName().contains("Nimbus")) {
UIManager.setLookAndFeel(lnfi.getClassName());
break;
}
}
} else {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
}
public void show(Window parent) {
JTextPane pane = new JTextPane();
pane.setOpaque(false);
pane.setContentType("text/html");
pane.setEditable(false);
pane.setText("<html>Test <a href=\"http://java.sun.com/\">java.sun.com</a>.</html>");
//"<html>Test <a href=\"http://www.digital-rapids.com/\">www.digital-rapids.com</a>.</html>");
System.out.println("document is a "+pane.getDocument().getClass().getName());
if (pane.getDocument() instanceof HTMLDocument) {
HTMLDocument htmlDoc = (HTMLDocument) pane.getDocument();
htmlDoc.getStyleSheet().addRule("body {font-family: Arial;}");
}
pane.setFont(Font.getFont(Font.SANS_SERIF));
pane.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
System.out.println("hyperlinkUpdate "+e.getEventType());
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
URI target = e.getURL().toURI();
Desktop.getDesktop().browse(target);
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
JOptionPane.showMessageDialog(
parent,
pane,
"Fails with Nimbus",
JOptionPane.ERROR_MESSAGE);
}
public static void main(String [] args) throws Exception {
new Main().show(null);
System.exit(0);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Don't use Nimbus