src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java

Print this page
rev 9343 : 8033716: Fix raw and unchecked lint warnings in com.sun.imageio
Reviewed-by: darcy, prr, bae

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -76,11 +76,11 @@
 
     /**
      * List of stream positions for images, reinitialized every time
      * a new input source is set.
      */
-    private List imagePositions = null;
+    private List<Long> imagePositions = null;
 
     /**
      * The number of images in the stream, or 0.
      */
     private int numImages = 0;

@@ -221,13 +221,13 @@
 
     /** The DisposerRecord that handles the actual disposal of this reader. */
     private DisposerRecord disposerRecord;
 
     /** Sets up static C structures. */
-    private static native void initReaderIDs(Class iisClass,
-                                             Class qTableClass,
-                                             Class huffClass);
+    private static native void initReaderIDs(Class<?> iisClass,
+                                             Class<?> qTableClass,
+                                             Class<?> huffClass);
 
     public JPEGImageReader(ImageReaderSpi originator) {
         super(originator);
         structPointer = initJPEGImageReader();
         disposerRecord = new JPEGReaderDisposerRecord(structPointer);

@@ -373,11 +373,11 @@
             imagePositions.add(new Long(savePos));
             // And set current image since we've read it now
             currentImage = 0;
         }
         if (seekForwardOnly) {
-            Long pos = (Long) imagePositions.get(imagePositions.size()-1);
+            Long pos = imagePositions.get(imagePositions.size()-1);
             iis.flushBefore(pos.longValue());
         }
         tablesOnlyChecked = true;
     }
 

@@ -390,10 +390,11 @@
         } finally {
             clearThreadLock();
         }
     }
 
+    @SuppressWarnings("fallthrough")
     private int getNumImagesOnThread(boolean allowSearch)
       throws IOException {
         if (numImages != 0) {
             return numImages;
         }

@@ -479,16 +480,16 @@
         }
         if (!tablesOnlyChecked) {
             checkTablesOnly();
         }
         if (imageIndex < imagePositions.size()) {
-            iis.seek(((Long)(imagePositions.get(imageIndex))).longValue());
+            iis.seek(imagePositions.get(imageIndex).longValue());
         } else {
             // read to start of image, saving positions
             // First seek to the last position we already have, and skip the
             // entire image
-            Long pos = (Long) imagePositions.get(imagePositions.size()-1);
+            Long pos = imagePositions.get(imagePositions.size()-1);
             iis.seek(pos.longValue());
             skipImage();
             // Now add all intervening positions, skipping images
             for (int index = imagePositions.size();
                  index <= imageIndex;

@@ -764,21 +765,21 @@
         } finally {
             clearThreadLock();
         }
     }
 
-    public Iterator getImageTypes(int imageIndex)
+    public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex)
         throws IOException {
         setThreadLock();
         try {
             return getImageTypesOnThread(imageIndex);
         } finally {
             clearThreadLock();
         }
     }
 
-    private Iterator getImageTypesOnThread(int imageIndex)
+    private Iterator<ImageTypeSpecifier> getImageTypesOnThread(int imageIndex)
         throws IOException {
         if (currentImage != imageIndex) {
             cbLock.check();
             readHeader(imageIndex, true);
         }

@@ -1061,11 +1062,11 @@
         WritableRaster imRas = null;
         int numImageBands = 0;
 
         if (!wantRaster){
             // Can we read this image?
-            Iterator imageTypes = getImageTypes(imageIndex);
+            Iterator<ImageTypeSpecifier> imageTypes = getImageTypes(imageIndex);
             if (imageTypes.hasNext() == false) {
                 throw new IIOException("Unsupported Image Type");
             }
 
             image = getDestination(param, imageTypes, width, height);

@@ -1185,12 +1186,12 @@
         initProgressData();
         // if we have a metadata object, we can count the scans
         // and set knownPassCount
         if (imageIndex == imageMetadataIndex) { // We have metadata
             knownPassCount = 0;
-            for (Iterator iter = imageMetadata.markerSequence.iterator();
-                 iter.hasNext();) {
+            for (Iterator<MarkerSegment> iter =
+                    imageMetadata.markerSequence.iterator(); iter.hasNext();) {
                 if (iter.next() instanceof SOSMarkerSegment) {
                     knownPassCount++;
                 }
             }
         }

@@ -1563,11 +1564,11 @@
         // reset C structures
         resetReader(structPointer);
 
         // reset local Java structures
         numImages = 0;
-        imagePositions = new ArrayList();
+        imagePositions = new ArrayList<>();
         currentImage = -1;
         image = null;
         raster = null;
         target = null;
         buffer = null;