src/share/classes/javax/imageio/ImageIO.java

Print this page
rev 9344 : 8034998: Fix raw and unchecked lint warnings in javax.imageio
Reviewed-by: darcy, prr

@@ -337,11 +337,11 @@
         throws IOException {
         if (input == null) {
             throw new IllegalArgumentException("input == null!");
         }
 
-        Iterator iter;
+        Iterator<ImageInputStreamSpi> iter;
         // Ensure category is present
         try {
             iter = theRegistry.getServiceProviders(ImageInputStreamSpi.class,
                                                    true);
         } catch (IllegalArgumentException e) {

@@ -349,11 +349,11 @@
         }
 
         boolean usecache = getUseCache() && hasCachePermission();
 
         while (iter.hasNext()) {
-            ImageInputStreamSpi spi = (ImageInputStreamSpi)iter.next();
+            ImageInputStreamSpi spi = iter.next();
             if (spi.getInputClass().isInstance(input)) {
                 try {
                     return spi.createInputStreamInstance(input,
                                                          usecache,
                                                          getCacheDirectory());

@@ -399,11 +399,11 @@
         throws IOException {
         if (output == null) {
             throw new IllegalArgumentException("output == null!");
         }
 
-        Iterator iter;
+        Iterator<ImageOutputStreamSpi> iter;
         // Ensure category is present
         try {
             iter = theRegistry.getServiceProviders(ImageOutputStreamSpi.class,
                                                    true);
         } catch (IllegalArgumentException e) {

@@ -411,11 +411,11 @@
         }
 
         boolean usecache = getUseCache() && hasCachePermission();
 
         while (iter.hasNext()) {
-            ImageOutputStreamSpi spi = (ImageOutputStreamSpi)iter.next();
+            ImageOutputStreamSpi spi = iter.next();
             if (spi.getOutputClass().isInstance(output)) {
                 try {
                     return spi.createOutputStreamInstance(output,
                                                           usecache,
                                                           getCacheDirectory());

@@ -510,24 +510,24 @@
                                    SpiInfo.FILE_SUFFIXES);
     }
 
     static class ImageReaderIterator implements Iterator<ImageReader> {
         // Contains ImageReaderSpis
-        public Iterator iter;
+        private Iterator<ImageReaderSpi> iter;
 
-        public ImageReaderIterator(Iterator iter) {
+        public ImageReaderIterator(Iterator<ImageReaderSpi> iter) {
             this.iter = iter;
         }
 
         public boolean hasNext() {
             return iter.hasNext();
         }
 
         public ImageReader next() {
             ImageReaderSpi spi = null;
             try {
-                spi = (ImageReaderSpi)iter.next();
+                spi = iter.next();
                 return spi.createReaderInstance();
             } catch (IOException e) {
                 // Deregister the spi in this case, but only as
                 // an ImageReaderSpi
                 theRegistry.deregisterServiceProvider(spi, ImageReaderSpi.class);

@@ -638,11 +638,11 @@
      */
     public static Iterator<ImageReader> getImageReaders(Object input) {
         if (input == null) {
             throw new IllegalArgumentException("input == null!");
         }
-        Iterator iter;
+        Iterator<ImageReaderSpi> iter;
         // Ensure category is present
         try {
             iter = theRegistry.getServiceProviders(ImageReaderSpi.class,
                                               new CanDecodeInputFilter(input),
                                               true);

@@ -700,11 +700,11 @@
         getImageReadersByFormatName(String formatName)
     {
         if (formatName == null) {
             throw new IllegalArgumentException("formatName == null!");
         }
-        Iterator iter;
+        Iterator<ImageReaderSpi> iter;
         // Ensure category is present
         try {
             iter = theRegistry.getServiceProviders(ImageReaderSpi.class,
                                     new ContainsFilter(readerFormatNamesMethod,
                                                        formatName),

@@ -736,11 +736,11 @@
     {
         if (fileSuffix == null) {
             throw new IllegalArgumentException("fileSuffix == null!");
         }
         // Ensure category is present
-        Iterator iter;
+        Iterator<ImageReaderSpi> iter;
         try {
             iter = theRegistry.getServiceProviders(ImageReaderSpi.class,
                                    new ContainsFilter(readerFileSuffixesMethod,
                                                       fileSuffix),
                                               true);

@@ -771,11 +771,11 @@
     {
         if (MIMEType == null) {
             throw new IllegalArgumentException("MIMEType == null!");
         }
         // Ensure category is present
-        Iterator iter;
+        Iterator<ImageReaderSpi> iter;
         try {
             iter = theRegistry.getServiceProviders(ImageReaderSpi.class,
                                       new ContainsFilter(readerMIMETypesMethod,
                                                          MIMEType),
                                               true);

@@ -824,24 +824,24 @@
                                    SpiInfo.FILE_SUFFIXES);
     }
 
     static class ImageWriterIterator implements Iterator<ImageWriter> {
         // Contains ImageWriterSpis
-        public Iterator iter;
+        private Iterator<ImageWriterSpi> iter;
 
-        public ImageWriterIterator(Iterator iter) {
+        public ImageWriterIterator(Iterator<ImageWriterSpi> iter) {
             this.iter = iter;
         }
 
         public boolean hasNext() {
             return iter.hasNext();
         }
 
         public ImageWriter next() {
             ImageWriterSpi spi = null;
             try {
-                spi = (ImageWriterSpi)iter.next();
+                spi = iter.next();
                 return spi.createWriterInstance();
             } catch (IOException e) {
                 // Deregister the spi in this case, but only as a writerSpi
                 theRegistry.deregisterServiceProvider(spi, ImageWriterSpi.class);
             }

@@ -883,11 +883,11 @@
         getImageWritersByFormatName(String formatName)
     {
         if (formatName == null) {
             throw new IllegalArgumentException("formatName == null!");
         }
-        Iterator iter;
+        Iterator<ImageWriterSpi> iter;
         // Ensure category is present
         try {
             iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                                     new ContainsFilter(writerFormatNamesMethod,
                                                        formatName),

@@ -917,11 +917,11 @@
         getImageWritersBySuffix(String fileSuffix)
     {
         if (fileSuffix == null) {
             throw new IllegalArgumentException("fileSuffix == null!");
         }
-        Iterator iter;
+        Iterator<ImageWriterSpi> iter;
         // Ensure category is present
         try {
             iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                                    new ContainsFilter(writerFileSuffixesMethod,
                                                       fileSuffix),

@@ -951,11 +951,11 @@
         getImageWritersByMIMEType(String MIMEType)
     {
         if (MIMEType == null) {
             throw new IllegalArgumentException("MIMEType == null!");
         }
-        Iterator iter;
+        Iterator<ImageWriterSpi> iter;
         // Ensure category is present
         try {
             iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                                       new ContainsFilter(writerMIMETypesMethod,
                                                          MIMEType),

@@ -1000,22 +1000,22 @@
             throw new IllegalArgumentException("reader == null!");
         }
 
         ImageReaderSpi readerSpi = reader.getOriginatingProvider();
         if (readerSpi == null) {
-            Iterator readerSpiIter;
+            Iterator<ImageReaderSpi> readerSpiIter;
             // Ensure category is present
             try {
                 readerSpiIter =
                     theRegistry.getServiceProviders(ImageReaderSpi.class,
                                                     false);
             } catch (IllegalArgumentException e) {
                 return null;
             }
 
             while (readerSpiIter.hasNext()) {
-                ImageReaderSpi temp = (ImageReaderSpi) readerSpiIter.next();
+                ImageReaderSpi temp = readerSpiIter.next();
                 if (temp.isOwnReader(reader)) {
                     readerSpi = temp;
                     break;
                 }
             }

@@ -1027,11 +1027,11 @@
         String[] writerNames = readerSpi.getImageWriterSpiNames();
         if (writerNames == null) {
             return null;
         }
 
-        Class writerSpiClass = null;
+        Class<?> writerSpiClass = null;
         try {
             writerSpiClass = Class.forName(writerNames[0], true,
                                            ClassLoader.getSystemClassLoader());
         } catch (ClassNotFoundException e) {
             return null;

@@ -1080,22 +1080,22 @@
             throw new IllegalArgumentException("writer == null!");
         }
 
         ImageWriterSpi writerSpi = writer.getOriginatingProvider();
         if (writerSpi == null) {
-            Iterator writerSpiIter;
+            Iterator<ImageWriterSpi> writerSpiIter;
             // Ensure category is present
             try {
                 writerSpiIter =
                     theRegistry.getServiceProviders(ImageWriterSpi.class,
                                                     false);
             } catch (IllegalArgumentException e) {
                 return null;
             }
 
             while (writerSpiIter.hasNext()) {
-                ImageWriterSpi temp = (ImageWriterSpi) writerSpiIter.next();
+                ImageWriterSpi temp = writerSpiIter.next();
                 if (temp.isOwnWriter(writer)) {
                     writerSpi = temp;
                     break;
                 }
             }

@@ -1107,11 +1107,11 @@
         String[] readerNames = writerSpi.getImageReaderSpiNames();
         if (readerNames == null) {
             return null;
         }
 
-        Class readerSpiClass = null;
+        Class<?> readerSpiClass = null;
         try {
             readerSpiClass = Class.forName(readerNames[0], true,
                                            ClassLoader.getSystemClassLoader());
         } catch (ClassNotFoundException e) {
             return null;

@@ -1158,11 +1158,11 @@
         }
         if (formatName == null) {
             throw new IllegalArgumentException("formatName == null!");
         }
 
-        Iterator iter;
+        Iterator<ImageWriterSpi> iter;
         // Ensure category is present
         try {
             iter = theRegistry.getServiceProviders(ImageWriterSpi.class,
                                  new CanEncodeImageAndFormatFilter(type,
                                                                    formatName),

@@ -1176,23 +1176,23 @@
 
     static class ImageTranscoderIterator
         implements Iterator<ImageTranscoder>
     {
         // Contains ImageTranscoderSpis
-        public Iterator iter;
+        public Iterator<ImageTranscoderSpi> iter;
 
-        public ImageTranscoderIterator(Iterator iter) {
+        public ImageTranscoderIterator(Iterator<ImageTranscoderSpi> iter) {
             this.iter = iter;
         }
 
         public boolean hasNext() {
             return iter.hasNext();
         }
 
         public ImageTranscoder next() {
             ImageTranscoderSpi spi = null;
-            spi = (ImageTranscoderSpi)iter.next();
+            spi = iter.next();
             return spi.createTranscoderInstance();
         }
 
         public void remove() {
             throw new UnsupportedOperationException();

@@ -1247,11 +1247,11 @@
         ImageReaderSpi readerSpi = reader.getOriginatingProvider();
         ImageWriterSpi writerSpi = writer.getOriginatingProvider();
         ServiceRegistry.Filter filter =
             new TranscoderFilter(readerSpi, writerSpi);
 
-        Iterator iter;
+        Iterator<ImageTranscoderSpi> iter;
         // Ensure category is present
         try {
             iter = theRegistry.getServiceProviders(ImageTranscoderSpi.class,
                                             filter, true);
         } catch (IllegalArgumentException e) {

@@ -1433,16 +1433,16 @@
         throws IOException {
         if (stream == null) {
             throw new IllegalArgumentException("stream == null!");
         }
 
-        Iterator iter = getImageReaders(stream);
+        Iterator<ImageReader> iter = getImageReaders(stream);
         if (!iter.hasNext()) {
             return null;
         }
 
-        ImageReader reader = (ImageReader)iter.next();
+        ImageReader reader = iter.next();
         ImageReadParam param = reader.getDefaultReadParam();
         reader.setInput(stream, true, true);
         BufferedImage bi;
         try {
             bi = reader.read(0, param);