-
Bug
-
Resolution: Fixed
-
P2
-
1.2.0
-
1.2fcs
-
x86, sparc
-
solaris_2.6, windows_95, windows_nt
-
Not verified
Name: ccC48265 Date: 12/30/97
IN BRIEF:
java.awt.Graphics.setColor(null) throws a NullPointerException
(NPE) because there is no protection against receiving a null
argument.
This is changed behavior from Java 1.0 and 1.1. I assume this
is an oversight because setFont which has the same structure as
setColor yet retains its check for null.
It is IMPORTANT to not allow these sorts of gratuitous
changes to the API since they will have a huge negative
effect on the installed base. I hope there are not many
more of this sort of thing...
FURTHER BACKGROUND:
I noticed this bug earlier in JDK1.2beta1. Upon inspecting
JDK1.2beta2, I found that the bug is still there.
I do not have a suitable test case for you; the bug is obvious
from inspection of the code. I can tell you that the problem
is in sun.awt.windows.WGraphics:
public void setColor(Color color)
{
super.setColor(color);
pSetForeground(color.getRGB());
}
The reference to color.getRGB causes a NPE. The other
routines throughout the Graphics hierarchy properly protect
setColor and setFont against receiving a null argument.
The definition of setColor should read:
public void setColor(Color color)
{
super.setColor(color);
if (color != null) {
pSetForeground(color.getRGB());
}
}
Again, it is IMPORTANT to fix this bug before final release,
because it will cause a great deal of unneccessary failures
and constitutes an undocumented and gratuitous change to
the Java API.
>----------------- Original Bug Report-------------------
>
>id : 21242
>category : java
>subcategory : classes_awt
>type : bug
>synopsis : Graphics.setColor(null) NPE
>description : java.awt.Graphics.setColor(null) throws a NullPointerException.
>
>This is changed behavior from Java 1.0 and 1.1. I assume this
>is an oversight because setFont which has the same structure as
>setColor yet retains its check for null.
>
>It is important to not allow these sorts of gratuitous
>changes to the API since they will have a huge negative
>effect on the installed base. I hope there are not many
>more of this sort of thing...
>comments : SysInfo='Axis P133 586/Pentium 133 96MB MS Internet Explorer 4.0'
SWVersion='Beta1' TesterSev='Moderate' TesterPri='Must fix' TesterFreq='Always'
BugID='BU-0163'
>workaround : Don't call Graphics.setColor(null) (which is a noop anyhow).
>But this won't work for the installed base of course.
(Review ID: 22508)
======================================================================
- duplicates
-
JDK-4162191 JBuilder File:New window is completely empty with JDK-1.2fcs-C
-
- Closed
-