8149810: TIFFField#getAsLong throws ClassCastException when data is type TIFFTag.TIFF_DOUBLE or TIFFTag.FLOAT
authorbpb
Fri, 29 Apr 2016 14:50:50 -0700
changeset 38393 2e49e69f3d64
parent 38392 d10be4336930
child 38394 2adb3640d70d
8149810: TIFFField#getAsLong throws ClassCastException when data is type TIFFTag.TIFF_DOUBLE or TIFFTag.FLOAT Summary: Expand the getAsLong() specification and handle the TIFF_DOUBLE and TIFF_FLOAT cases. Reviewed-by: prr
jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFField.java
--- a/jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFField.java	Fri Apr 29 11:54:18 2016 -0700
+++ b/jdk/src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFField.java	Fri Apr 29 14:50:50 2016 -0700
@@ -1089,6 +1089,15 @@
      * {@code TIFF_SBYTE} data will be returned in the range
      * [-128, 127].
      *
+     * <p> Data in {@code TIFF_FLOAT} and {@code TIFF_DOUBLE} are
+     * simply cast to {@code long} and may suffer from truncation.
+     *
+     * <p> Data in {@code TIFF_SRATIONAL} or
+     * {@code TIFF_RATIONAL} format are evaluated by dividing the
+     * numerator into the denominator using double-precision
+     * arithmetic and then casting to {@code long}.  Loss of
+     * precision and truncation may occur.
+     *
      * <p> Data in {@code TIFF_ASCII} format will be parsed as by
      * the {@code Double.parseDouble} method, with the result
      * cast to {@code long}.
@@ -1112,6 +1121,10 @@
         case TIFFTag.TIFF_LONG:
         case TIFFTag.TIFF_IFD_POINTER:
             return ((long[])data)[index];
+        case TIFFTag.TIFF_FLOAT:
+            return (long)((float[])data)[index];
+        case TIFFTag.TIFF_DOUBLE:
+            return (long)((double[])data)[index];
         case TIFFTag.TIFF_SRATIONAL:
             int[] ivalue = getAsSRational(index);
             return (long)((double)ivalue[0]/ivalue[1]);