United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4632623 : java.awt.Checkbox.getLabel() returns "" if no label

Details
Type:
Bug
Submit Date:
2002-02-04
Status:
Closed
Updated Date:
2004-09-14
Project Name:
JDK
Resolved Date:
2003-05-25
Component:
client-libs
OS:
solaris_7,solaris_10
Sub-Component:
java.awt
CPU:
sparc
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.0,5.0
Fixed Versions:
5.0 (tiger)

Related Reports

Sub Tasks

Description
Name: sdR10048			Date: 02/04/2002


JDK1.4rc92
java.awt.Checkbox method 

public String getLabel()

returns "" string if checkbox has no label.
But null is expected here as spec says.
See demo test.


Spec says:
----------
public String getLabel()

    Gets the label of this check box.
Returns:
    the label of this check box, or null if this check box has no label.
See_Also:
    setLabel(java.lang.String)


Demo test:
----------
import java.awt.*;
public class Test {
    public static void main(String[] args) {
        System.out.println("\""+(new Checkbox()).getLabel()+"\"");
    }
}


Demo output:
----------
[archer] ~/tmp
% java Test 
""
        
======================================================================

                                    

Comments
SUGGESTED FIX

Name: rpR10076			Date: 07/10/2003


***************
*** 68,76 ****

      /**
       * The label of the Checkbox.
!        * This field can be null. If a label is not specified it
!        * defaults to null or "".
!        * @serial
       * @see #getLabel()
       * @see #setLabel(label)
       */
--- 68,75 ----

      /**
       * The label of the Checkbox.
!      * This field can be null.
!      * @serial
       * @see #getLabel()
       * @see #setLabel(label)
       */
***************
*** 117,125 ****
      }

      /**
!      * Creates a check box with no label. The state of this
!      * check box is set to "off," and it is not part of any
!      * check box group.
       * @exception HeadlessException if GraphicsEnvironment.isHeadless()
       * returns true
       * @see java.awt.GraphicsEnvironment#isHeadless
--- 116,124 ----
      }

      /**
!      * Creates a check box with an empty string for its label.
!      * The state of this check box is set to "off," and it is not
!      * part of any check box group.
       * @exception HeadlessException if GraphicsEnvironment.isHeadless()
       * returns true
       * @see java.awt.GraphicsEnvironment#isHeadless

======================================================================
                                     
2004-09-15
EVALUATION

We should update the spec, and be clear about null vs. empty string for 
ctors, setLabel, getLabel, etc.  
###@###.### 2002-02-04

Unfortunately, the spec explicitly says null, while we believe that the current
behaviour is more correct than the spec. Moreover, if we change the behaviour
now to match the spec, existing apps can start throwing NPEs.
We can't chnage the spec this way in update release, too, so we have to commit
this bug to tiger instead.
###@###.### 2002-09-12

Name: rpR10076			Date: 07/10/2003


The decision was to change the documentation rather than the implementation.
CCC-daemon announcement from 2003/04/28 says about the approval.
So the behaviour is now correct.
Please see diffs to Checkbox.java doc in suggested fix section.

======================================================================
                                     
2004-09-15
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger

FIXED IN:
tiger

INTEGRATED IN:
tiger
tiger-b08

VERIFIED IN:
1.5


                                     
2004-09-15



Hardware and Software, Engineered to Work Together