-
Enhancement
-
Resolution: Unresolved
-
P5
-
1.4.0
-
x86
-
linux
Name: jk109818 Date: 01/16/2002
FULL PRODUCT VERSION :
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
Problem also occurs under 1.3.1_02.
glibc-2.1.3-21
Linux jesse_laptop.netbeans.com 2.2.12-20 #1 Mon Sep 27
10:40:35 EDT 1999 i686 unknown
Red Hat Linux release 6.1 (Cartman)
A DESCRIPTION OF THE PROBLEM :
Error reporting and management from
UIManager.getUI(JComponent) is very bad. If the
createUI(JComponent) method in the UI class throws some
unchecked exception, it is completely swallowed and a
meaningless stack trace is printed from UIManager. If you
did not write the UI class yourself and are trying to track
down a bug in someone else's code, it is essentially
impossible to get the information you need without creating
a patched version of UIManager.java and putting it in your
boot classpath.
Furthermore, if an error does occur, the method returns
null, in violation of its Javadoc:
http://java.sun.com/j2se/1.4/docs/api/javax/swing/UIManager.html#getUI(javax.swing.JComponent)
which does not mention a possible null return value.
Please (1) find some way to get the original message and
stack trace from an error thrown and caught by
UIManager.getUI and print it to console for use in tracking
down problems; (2) if null must be returned in case of an
error, please document in the Javadoc that this is so.
Ideally getUI would throw some sort of exception (e.g.
InvocationTargetException) that could encapsulate the
original problem, solving both problems at once, but it is a
little late for that now.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the test program.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected: some stack trace of the NullPointerException
including the detail message "message here!"; either a
non-null return value from getUI or an exception thrown from it.
Actually got: a useless stack trace with no information, and
a null return value:
createUI called
UIDefaults.getUI() failed: createUI() failed for
testuidef.TestUIDefaultsErrorRecovery$SomeComponent[,0,0,0x0,invalid,alignmentX=null,alignmentY=null,border=,flags=0,maximumSize=,minimumSize=,preferredSize=]
java.lang.reflect.InvocationTargetException
java.lang.Error
at javax.swing.UIDefaults.getUIError(UIDefaults.java:689)
at javax.swing.UIDefaults.getUI(UIDefaults.java:735)
at javax.swing.UIManager.getUI(UIManager.java:787)
at
testuidef.TestUIDefaultsErrorRecovery.main(TestUIDefaultsErrorRecovery.java:7)
null
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package testuidef;
import javax.swing.*;
import javax.swing.plaf.*;
public class TestUIDefaultsErrorRecovery {
public static void main(String[] args) {
UIManager.getDefaults().putDefaults(new Object[] {"SCUI",
"testuidef.TestUIDefaultsErrorRecovery$ImplSCUI"});
System.out.println(UIManager.getUI(new SomeComponent()));
}
public static class SomeComponent extends JComponent {
public String getUIClassID() { return "SCUI"; }
}
public static class ImplSCUI extends ComponentUI {
public static ComponentUI createUI(JComponent jc) {
System.out.println("createUI called");
throw new NullPointerException("message here!");
//return new ImplSCUI();
}
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Getting JDK source and patching UIManager.java so that in
getUI a stack trace is inserted:
// ...
catch (Exception e) {
e.printStackTrace(); // <-- here
getUIError("createUI() failed for " + target
+ " " + e);
}
// ...
(Review ID: 138329)
======================================================================