-
Bug
-
Resolution: Fixed
-
P4
-
8, 9
-
b135
-
generic
-
generic
FULL PRODUCT VERSION :
java version "1.8.0_71"
Java(TM) SE Runtime Environment (build 1.8.0_71-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.71-b15, mixed mode)
A DESCRIPTION OF THE PROBLEM :
javax/imageio/ImageIO.java contains the following code:
private static <S extends ImageReaderWriterSpi>
String[] getReaderWriterInfo(Class<S> spiClass, SpiInfo spiInfo)
{
// Ensure category is present
Iterator<S> iter;
try {
iter = theRegistry.getServiceProviders(spiClass, true);
} catch (IllegalArgumentException e) {
return new String[0];
}
HashSet<String> s = new HashSet<String>();
while (iter.hasNext()) {
ImageReaderWriterSpi spi = iter.next();
Collections.addAll(s, spiInfo.info(spi));
}
return s.toArray(new String[s.size()]);
}
This method here:
Collections.addAll(s, spiInfo.info(spi));
Ultimately delegates to getMIMETypes():
MIME_TYPES {
@Override
String[] info(ImageReaderWriterSpi spi) {
return spi.getMIMETypes();
}
},
getMIMETypes() is clearly documented as potentially returning null, and the implementation clearly can, and does:
/**
---- omitting ----
* @return an array of <code>String</code>s or length at least 1
* containing MIME types associated with this reader or writer, or
* <code>null</code>.
*/
public String[] getMIMETypes() {
return MIMETypes == null ? null : (String[])MIMETypes.clone();
}
So all you need is one provider in the classpath which has no MIME types defined, which isn't very hard to come by.
This failure to detect the null then triggers a NullPointerException from allAll:
Caused by: java.lang.NullPointerException
at java.util.Collections.addAll(Collections.java:5400)
at javax.imageio.ImageIO.getReaderWriterInfo(ImageIO.java:468)
at javax.imageio.ImageIO.getReaderMIMETypes(ImageIO.java:496)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Caused by: java.lang.NullPointerException
at java.util.Collections.addAll(Collections.java:5400)
at javax.imageio.ImageIO.getReaderWriterInfo(ImageIO.java:468)
at javax.imageio.ImageIO.getReaderMIMETypes(ImageIO.java:496)
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Workaround is presumably to avoid calling ImageIO.getReaderMIMETypes() and similar methods and implement the same iteration correctly in the client code.
java version "1.8.0_71"
Java(TM) SE Runtime Environment (build 1.8.0_71-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.71-b15, mixed mode)
A DESCRIPTION OF THE PROBLEM :
javax/imageio/ImageIO.java contains the following code:
private static <S extends ImageReaderWriterSpi>
String[] getReaderWriterInfo(Class<S> spiClass, SpiInfo spiInfo)
{
// Ensure category is present
Iterator<S> iter;
try {
iter = theRegistry.getServiceProviders(spiClass, true);
} catch (IllegalArgumentException e) {
return new String[0];
}
HashSet<String> s = new HashSet<String>();
while (iter.hasNext()) {
ImageReaderWriterSpi spi = iter.next();
Collections.addAll(s, spiInfo.info(spi));
}
return s.toArray(new String[s.size()]);
}
This method here:
Collections.addAll(s, spiInfo.info(spi));
Ultimately delegates to getMIMETypes():
MIME_TYPES {
@Override
String[] info(ImageReaderWriterSpi spi) {
return spi.getMIMETypes();
}
},
getMIMETypes() is clearly documented as potentially returning null, and the implementation clearly can, and does:
/**
---- omitting ----
* @return an array of <code>String</code>s or length at least 1
* containing MIME types associated with this reader or writer, or
* <code>null</code>.
*/
public String[] getMIMETypes() {
return MIMETypes == null ? null : (String[])MIMETypes.clone();
}
So all you need is one provider in the classpath which has no MIME types defined, which isn't very hard to come by.
This failure to detect the null then triggers a NullPointerException from allAll:
Caused by: java.lang.NullPointerException
at java.util.Collections.addAll(Collections.java:5400)
at javax.imageio.ImageIO.getReaderWriterInfo(ImageIO.java:468)
at javax.imageio.ImageIO.getReaderMIMETypes(ImageIO.java:496)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Caused by: java.lang.NullPointerException
at java.util.Collections.addAll(Collections.java:5400)
at javax.imageio.ImageIO.getReaderWriterInfo(ImageIO.java:468)
at javax.imageio.ImageIO.getReaderMIMETypes(ImageIO.java:496)
REPRODUCIBILITY :
This bug can be reproduced always.
CUSTOMER SUBMITTED WORKAROUND :
Workaround is presumably to avoid calling ImageIO.getReaderMIMETypes() and similar methods and implement the same iteration correctly in the client code.