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)