8148628: TIFFDirectory(getAsMetaData) created with one TIFFField having a IFD pointer tag throws ClassCastException & other naming differences (JEP 262)
Summary: Clean up some handling of TIFFDirectory instances contained in TIFFFields and make a couple of minor changes to Exif and GeoTIFF tag names.
Reviewed-by: prr
--- a/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFFieldNode.java Mon Feb 08 09:41:53 2016 -0800
+++ b/jdk/src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFFieldNode.java Mon Feb 01 15:00:02 2016 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, 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
@@ -39,7 +39,7 @@
*/
public class TIFFFieldNode extends IIOMetadataNode {
private static String getNodeName(TIFFField f) {
- return f.getData() instanceof TIFFDirectory ?
+ return (f.hasDirectory() || f.getData() instanceof TIFFDirectory) ?
"TIFFIFD" : "TIFFField";
}
@@ -52,7 +52,8 @@
public TIFFFieldNode(TIFFField field) {
super(getNodeName(field));
- isIFD = field.getData() instanceof TIFFDirectory;
+ isIFD = field.hasDirectory() ||
+ field.getData() instanceof TIFFDirectory;
this.field = field;
@@ -68,7 +69,8 @@
setAttribute("parentTagName", tagName);
}
- TIFFDirectory dir = (TIFFDirectory)field.getData();
+ TIFFDirectory dir = field.hasDirectory() ?
+ field.getDirectory() : (TIFFDirectory)field.getData();
TIFFTagSet[] tagSets = dir.getTagSets();
if(tagSets != null) {
StringBuilder tagSetNames = new StringBuilder();
@@ -90,7 +92,8 @@
if(isInitialized) return;
if(isIFD) {
- TIFFDirectory dir = (TIFFDirectory)field.getData();
+ TIFFDirectory dir = field.hasDirectory() ?
+ field.getDirectory() : (TIFFDirectory)field.getData();
TIFFField[] fields = dir.getTIFFFields();
if(fields != null) {
TIFFTagSet[] tagSets = dir.getTagSets();
--- a/jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/ExifTIFFTagSet.java Mon Feb 08 09:41:53 2016 -0800
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/ExifTIFFTagSet.java Mon Feb 01 15:00:02 2016 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, 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
@@ -1256,7 +1256,7 @@
static class ExifVersion extends TIFFTag {
public ExifVersion() {
- super("Exifversion",
+ super("ExifVersion",
TAG_EXIF_VERSION,
1 << TIFFTag.TIFF_UNDEFINED,
4);
--- a/jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/GeoTIFFTagSet.java Mon Feb 08 09:41:53 2016 -0800
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/GeoTIFFTagSet.java Mon Feb 01 15:00:02 2016 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, 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
@@ -97,7 +97,7 @@
static class GeoKeyDirectory extends TIFFTag {
public GeoKeyDirectory() {
- super("GeoKeyDirectory",
+ super("GeoKeyDirectoryTag",
TAG_GEO_KEY_DIRECTORY,
1 << TIFFTag.TIFF_SHORT);
}
@@ -105,7 +105,7 @@
static class GeoDoubleParams extends TIFFTag {
public GeoDoubleParams() {
- super("GeoDoubleParams",
+ super("GeoDoubleParamsTag",
TAG_GEO_DOUBLE_PARAMS,
1 << TIFFTag.TIFF_DOUBLE);
}
@@ -113,7 +113,7 @@
static class GeoAsciiParams extends TIFFTag {
public GeoAsciiParams() {
- super("GeoAsciiParams",
+ super("GeoAsciiParamsTag",
TAG_GEO_ASCII_PARAMS,
1 << TIFFTag.TIFF_ASCII);
}
--- a/jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFDirectory.java Mon Feb 08 09:41:53 2016 -0800
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFDirectory.java Mon Feb 01 15:00:02 2016 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, 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
@@ -219,11 +219,23 @@
TIFFField f = fields[i];
TIFFTag tag = f.getTag();
if(tag.isIFDPointer()) {
- TIFFDirectory subIFD =
- getDirectoryAsIFD((TIFFDirectory)f.getData());
- f = new TIFFField(tag, f.getType(), (long)f.getCount(), subIFD);
+ TIFFDirectory subDir = null;
+ if (f.hasDirectory()) {
+ subDir = f.getDirectory();
+ } else if (f.getData() instanceof TIFFDirectory) {
+ subDir = (TIFFDirectory)f.getData();
+ }
+ if (subDir != null) {
+ TIFFDirectory subIFD = getDirectoryAsIFD(subDir);
+ f = new TIFFField(tag, f.getType(), (long)f.getCount(),
+ subIFD);
+ } else {
+ f = null;
+ }
}
- ifd.addTIFFField(f);
+ if (f != null) {
+ ifd.addTIFFField(f);
+ }
}
return ifd;