JDK-4527255 : FilteredImageSource.addConsumer(null) throws NullPointerException
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: solaris_7
  • CPU: sparc
  • Submitted: 2001-11-14
  • Updated: 2001-11-14
  • Resolved: 2001-11-14
Related Reports
Relates :  
Description
FilteredImageSource.addConsumer(null), removeConsumer(null) and 
isConsumer(null) throws NullPointerException. NullPointerException either needs to be specified or shoule not be thrown. isConsumer(null) is better to return
false.

import java.awt.image.*;

public class NullTest {
    public static void main(String[] args) {

        ImageProducer imgp = new MemoryImageSource(
                                 5, 5, new int[20], 0, 5);
        ImageFilter imgf = new ReplicateScaleFilter(3, 3);
        FilteredImageSource s = new FilteredImageSource(imgp, imgf);
        try {
            s.addConsumer((ImageConsumer) null);
        } catch (NullPointerException e) {
            System.out.println("addConsumer(null) throws NullPointerException");
            e.printStackTrace();
        }
        try {
            if (s.isConsumer((ImageConsumer) null)) {
                System.out.println("null should not be a consumer");
            }
        } catch (NullPointerException e) {
            System.out.println("isConsumer(null) throws NullPointerException");
            e.printStackTrace();
        }
        try {
            s.removeConsumer((ImageConsumer) null);
        } catch (NullPointerException e) {
            System.out.println("removeConsumer(null) throws NullPointerException");
            e.printStackTrace();
        }
        
    }
}

output:

addConsumer(null) throws NullPointerException
java.lang.NullPointerException
        at java.util.Hashtable.containsKey(Hashtable.java:308)
        at java.awt.image.FilteredImageSource.addConsumer(FilteredImageSource.ja
va:68)
        at NullTest.main(NullTest.java:11)
isConsumer(null) throws NullPointerException
java.lang.NullPointerException
        at java.util.Hashtable.containsKey(Hashtable.java:308)
        at java.awt.image.FilteredImageSource.isConsumer(FilteredImageSource.jav
a:83)
        at NullTest.main(NullTest.java:17)
removeConsumer(null) throws NullPointerException
java.lang.NullPointerException
        at java.util.Hashtable.get(Hashtable.java:329)
        at java.awt.image.FilteredImageSource.removeConsumer(FilteredImageSource
.java:93)
        at NullTest.main(NullTest.java:25)

Comments
EVALUATION This is a user error. The user is not supposed to be calling addConsumer(), etc. These methods are only called by classes that implement the ImageConsumer/ImageProducer interfaces. ###@###.### 2001-11-14 =========================== This is user error. Also the submitter makes an incorrect assertion that a runtime error that may be thrown as a result of buggy application code must be part of the specification. This is wrong. Although some are, there is no requirement or reason for all runtime errors to be to be either declared or documented and any conformance test which makes assumptions which aren't documented is invalid. ###@###.### 2001-11-14 ============================
14-11-2001