public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug SWING/22616] New: new ImageIcon().getIconHeight() throws NPE
@ 2005-07-22 19:09 timo dot lindfors at iki dot fi
  2005-07-22 19:12 ` [Bug SWING/22616] " timo dot lindfors at iki dot fi
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: timo dot lindfors at iki dot fi @ 2005-07-22 19:09 UTC (permalink / raw)
  To: java-prs

Steps to reproduce:
1. Compile and run the attached testcase.

Expected results:
1. Program prints out "-1".

Actual results:
1. Program throws the following exception:
java.lang.NullPointerException
   at javax.swing.ImageIcon.getIconHeight (ImageIcon.java:300)
   at testcase.<init> (testcase.java:9)
   at testcase.main (testcase.java:5)

Testcase:
import javax.swing.*;
import java.awt.*;
public class testcase {
        public static void main(String[] args) {
                new testcase();
        }
        public testcase() {
                ImageIcon icon = new ImageIcon();
                System.out.println(icon.getIconHeight());
        }
}

Note:
Severity is set to minor since error handling in Icon is probably undefined
behavior anyway since the javadoc does not say anything about what
getIconHeight() should return when no icon is loaded. Sun's JDK 1.5.0 returns -1
and so applications have started to depend on this undefined behavior.

Proposed fix:
Return -1 in getIconHeight() and getIconWidth() if no icon is loaded.

---
/home/lindi/cp-src/2005-07-22T100134+0000/classpath/javax/swing/ImageIcon.java.~1.16.~      2005-07-02 23:32:47.000000000 +0300
+++
/home/lindi/cp-src/2005-07-22T100134+0000/classpath/javax/swing/ImageIcon.java  
   2005-07-22 21:38:05.000000000 +0300
@@ -297,11 +297,15 @@

   public int getIconHeight()
   {
+    if (image == null)
+      return -1;
     return image.getHeight(observer);
   }

   public int getIconWidth()
   {
+    if (image == null)
+      return -1;
     return image.getWidth(observer);
   }

-- 
           Summary: new ImageIcon().getIconHeight() throws NPE
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: minor
          Priority: P2
         Component: SWING
        AssignedTo: graydon at redhat dot com
        ReportedBy: timo dot lindfors at iki dot fi
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22616


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug SWING/22616] new ImageIcon().getIconHeight() throws NPE
  2005-07-22 19:09 [Bug SWING/22616] New: new ImageIcon().getIconHeight() throws NPE timo dot lindfors at iki dot fi
@ 2005-07-22 19:12 ` timo dot lindfors at iki dot fi
  2005-07-22 19:13 ` pinskia at gcc dot gnu dot org
  2005-08-21 18:30 ` [Bug swing/22616] " fitzsim at redhat dot com
  2 siblings, 0 replies; 5+ messages in thread
From: timo dot lindfors at iki dot fi @ 2005-07-22 19:12 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From timo dot lindfors at iki dot fi  2005-07-22 19:12 -------
Created an attachment (id=9331)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=9331&action=view)
Return -1 in getIconHeight() and getIconWidth() if no icon is loaded.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22616


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug SWING/22616] new ImageIcon().getIconHeight() throws NPE
  2005-07-22 19:09 [Bug SWING/22616] New: new ImageIcon().getIconHeight() throws NPE timo dot lindfors at iki dot fi
  2005-07-22 19:12 ` [Bug SWING/22616] " timo dot lindfors at iki dot fi
@ 2005-07-22 19:13 ` pinskia at gcc dot gnu dot org
  2005-08-21 18:30 ` [Bug swing/22616] " fitzsim at redhat dot com
  2 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-07-22 19:13 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-07-22 19:13 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-07-22 19:13:38
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22616


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug swing/22616] new ImageIcon().getIconHeight() throws NPE
  2005-07-22 19:09 [Bug SWING/22616] New: new ImageIcon().getIconHeight() throws NPE timo dot lindfors at iki dot fi
  2005-07-22 19:12 ` [Bug SWING/22616] " timo dot lindfors at iki dot fi
  2005-07-22 19:13 ` pinskia at gcc dot gnu dot org
@ 2005-08-21 18:30 ` fitzsim at redhat dot com
  2 siblings, 0 replies; 5+ messages in thread
From: fitzsim at redhat dot com @ 2005-08-21 18:30 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From fitzsim at redhat dot com  2005-08-21 18:30 -------
Patch committed, thanks.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22616


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug swing/22616] new ImageIcon().getIconHeight() throws NPE
       [not found] <bug-22616-9422@http.gcc.gnu.org/bugzilla/>
@ 2005-10-16  1:47 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-10-16  1:47 UTC (permalink / raw)
  To: java-prs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |0.18


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22616


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-10-16  1:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-22 19:09 [Bug SWING/22616] New: new ImageIcon().getIconHeight() throws NPE timo dot lindfors at iki dot fi
2005-07-22 19:12 ` [Bug SWING/22616] " timo dot lindfors at iki dot fi
2005-07-22 19:13 ` pinskia at gcc dot gnu dot org
2005-08-21 18:30 ` [Bug swing/22616] " fitzsim at redhat dot com
     [not found] <bug-22616-9422@http.gcc.gnu.org/bugzilla/>
2005-10-16  1:47 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).