-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
beta2
-
generic
-
generic
Name: bkR10012 Date: 04/18/2001
Spec. of the class javax.imageio.ImageReader says:
"processWarningOccurred
protected void processWarningOccurred(String baseName,
String keyword)
Broadcasts a localized warning message to all registered
IIOReadWarningListeners by calling their warningOccurred
method with a string taken from a ResourceBundle."
Spec. doesn't describe any exceptions for this method.
But method processWarningOccurred throws unexpected exceptions
in following cases:
NullPointerException - if locale has not been set when listener is added
NullPointerException - if baseName or keyword is null
MissingResourceException - if no resource bundle for the specified
base name can be found
MissingResourceException - if no object for the given key can be found
ClassCastException - if the object found for the given key is not a string
See test source and log below.
---------------------------------------- test.java
import javax.imageio.*;
import javax.imageio.event.*;
import javax.imageio.spi.*;
import javax.imageio.metadata.*;
import java.util.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
public class test {
public static void main(String argv[]) {
DummyImageReaderImpl ireader;
MyReadWarningListener rwl;
Locale[] locales = {new Locale("ru"),
new Locale("fr"),
new Locale("uk"),
};
Locale new_locale;
ireader = new DummyImageReaderImpl(null);
rwl = new MyReadWarningListener();
ireader.addIIOReadWarningListener(rwl);
ireader.setAvailableLocales(locales);
new_locale = new Locale("fr");
ireader.setLocale(new_locale);
try {
ireader.processWarningOccurred("Stats", "water");
} catch (Throwable ee) {
System.out.println("Unexpected exception 1: " + ee);
}
ireader.removeAllIIOReadWarningListeners();
ireader.addIIOReadWarningListener(rwl);
try {
ireader.processWarningOccurred("NonExistent", "water");
} catch (Throwable ee) {
System.out.println("Unexpected exception 2: " + ee);
}
try {
ireader.processWarningOccurred("Stats", "anyKey");
} catch (Throwable ee) {
System.out.println("Unexpected exception 3: " + ee);
}
try {
ireader.processWarningOccurred(null, "water");
} catch (Throwable ee) {
System.out.println("Unexpected exception 4: " + ee);
}
try {
ireader.processWarningOccurred("Stats", null);
} catch (Throwable ee) {
System.out.println("Unexpected exception 5: " + ee);
}
try {
ireader.processWarningOccurred("Stats", "int");
} catch (Throwable ee) {
System.out.println("Unexpected exception 6: " + ee);
}
ireader.processWarningOccurred("Stats", "water");
}
}
class DummyImageReaderImpl extends ImageReader {
public DummyImageReaderImpl(ImageReaderSpi originatingProvider) {
super(originatingProvider);
}
public void processWarningOccurred(String baseName, String keyword) {
super.processWarningOccurred(baseName, keyword);
}
public void setAvailableLocales(Locale[] locales) {
if (locales == null || locales.length == 0)
availableLocales = null;
else
availableLocales = (Locale[])locales.clone();
}
public int getNumImages(boolean allowSearch)
throws IOException {return 1;}
public int getWidth(int imageIndex) throws IOException {return 1;}
public int getHeight(int imageIndex) throws IOException {return 1;}
public Iterator getImageTypes(int imageIndex)
throws IOException {return null;}
public IIOMetadata getStreamMetadata()
throws IOException {return null;}
public IIOMetadata getImageMetadata(int imageIndex)
throws IOException {return null;}
public BufferedImage read(int imageIndex, ImageReadParam param)
throws IOException {return null;}
}
class MyReadWarningListener implements IIOReadWarningListener {
public void warningOccurred(ImageReader source, String warning) {
System.out.println(warning);
}
}
---------------------------------------- Stats_fr.java
import java.util.*;
public class Stats_fr extends ListResourceBundle {
public Object[][] getContents(){
return contents;
}
private Object[][] contents = {
{"coffee", new String("coffee from Stats_fr class")},
{"tea", new String("tea from Stats_fr class")},
{"water", new String("water from Stats_fr class")},
{"int", new Integer(1)}
};
}
----------------------------------------
% java -version
java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b60)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b60, mixed mode)
% java test
Unexpected exception 1: java.lang.NullPointerException
Unexpected exception 2: java.util.MissingResourceException: Can't find
bundle for base name NonExistent, locale fr
Unexpected exception 3: java.util.MissingResourceException: Can't find
resource for bundle Stats_fr, key anyKey
Unexpected exception 4: java.lang.NullPointerException
Unexpected exception 5: java.lang.NullPointerException
Unexpected exception 6: java.lang.ClassCastException: java.lang.Integer
water from Stats_fr class
----------------------------------------
This bug causes failure of the new JCK test
api/javax_imageio/ImageReader/index.html#readWarningListener
======================================================================
Name: bkR10012 Date: 05/11/2001
The method processWarningOccurred in javax.imageio.ImageWriter
also throws the same unexpected exceptions in the same cases.
This bug causes failure of the new JCK test
api/javax_imageio/ImageWriter/index.html#writeWarningListener
======================================================================