changeset 16295:cdde8f59b6b5

8153208: TIFFImageReadParam: should "contains()" check be appropriate for addAllowedTagSet() method? Summary: Do not add a duplicate TIFFTagSet instance and update the spec accordingly. Reviewed-by: prr
author bpb
date Tue, 15 Nov 2016 08:58:29 -0800
parents b0a97708f993
children df2f48c5d4dd
files src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFImageReadParam.java
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFImageReadParam.java	Tue Nov 15 12:52:24 2016 +0530
+++ b/src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFImageReadParam.java	Tue Nov 15 08:58:29 2016 -0800
@@ -50,7 +50,8 @@
  */
 public final class TIFFImageReadParam extends ImageReadParam {
 
-    private List<TIFFTagSet> allowedTagSets = new ArrayList<TIFFTagSet>(4);
+    private final List<TIFFTagSet> allowedTagSets =
+        new ArrayList<TIFFTagSet>(4);
 
     /**
      * Constructs a {@code TIFFImageReadParam}.  Tags defined by
@@ -72,7 +73,8 @@
 
     /**
      * Adds a {@code TIFFTagSet} object to the list of allowed
-     * tag sets.
+     * tag sets.  Attempting to add a duplicate object to the list
+     * has no effect.
      *
      * @param tagSet a {@code TIFFTagSet}.
      *
@@ -83,7 +85,9 @@
         if (tagSet == null) {
             throw new IllegalArgumentException("tagSet == null!");
         }
-        allowedTagSets.add(tagSet);
+        if (!allowedTagSets.contains(tagSet)) {
+            allowedTagSets.add(tagSet);
+        }
     }
 
     /**