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
--- a/jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFImageReadParam.java Tue Nov 15 12:52:24 2016 +0530
+++ b/jdk/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);
+ }
}
/**