-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
beta
-
sparc
-
solaris_2.6
Name: nkR10003 Date: 08/11/2000
JDesktopIcon.get(Maximum)MinimumSize() methods throw NullPointerException.
JavaDoc comments for JComponent.getMinimumSize() state: "If the minimum size has been set to
a non-null value just returns it. If the UI delegate's getMinimumSize() method returns a
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
non-null value then return that;" So UI delegate's getMinimumSize() should be invoked in case
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
minimum size has not been set. If Metal UI delegate has been installed
MetalDesktopIconUI.getMinimumSize(JComponent) throws NullPointerException. This happens
because of invalid overloading installComponents method in MetalDesktopIconUI class. This
method does not call super.installComponents() and therefore does not initialize components
which are necessary for apropriate functioning of _inherited_ methods (get(Maximum)MinimumSize
just the case).
See piece of code source below:
//BasicDesktopIconUI
protected void installComponents() {
............
iconPane = new BasicInternalFrameTitlePane(frame);
............
}
public Dimension getMinimumSize(JComponent c) {
return iconPane.getMinimumSize();
}
public Dimension getMaximumSize(JComponent c){
return iconPane.getMaximumSize();
}
//MetalDesktopIconUI
1. installComponents method is overloaded in the class
2. nothing about iconPane field in the class
3. no super.installComponents() call in the class
4. get(Maximum)MinimumSize methods are not overloaded
Example below demonstrates this problem:
------------------example--------------------
//test.java
import javax.swing.*;
class test {
public static void main(String[] args) {
JInternalFrame.JDesktopIcon icon =
new JInternalFrame.JDesktopIcon(new JInternalFrame());
System.out.println("icon.getUI: " +
icon.getUI());
System.out.println("icon.getMinimumSize: " +
icon.getMinimumSize());
System.out.println("icon.getUI().getMinimumSize: " +
icon.getUI().getMinimumSize(icon));
System.out.println("Passed: OKAY");
System.exit(0);
}
}
----------------output:----------------------
icon.getUI: javax.swing.plaf.metal.MetalDesktopIconUI@482923
Exception in thread "main" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicDesktopIconUI.getMinimumSize(BasicDesktopIconUI.java:115)
at javax.swing.JComponent.getMinimumSize(JComponent.java:1130)
at test.main(test.java:7)
---------------------------------------------
======================================================================