Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4894894

JPGMetadata.getAsTree() throws IllegalArgException for standard mdata format

    XMLWordPrintable

    Details

      Description

      I am getting the default stream metadata from JPEGImageWriter using writer.getDefaultStreamMetadata(param). From this IIOMetadata object i retrieved the supported metadata format names by calling getMetadataFormatNames(). It returned 2 values which are given below.
      javax_imageio_jpeg_stream_1.0 (Native)
      javax_imageio_1.0 (Standard)

      I tried to get the DOM tree for both the formats given above and I called IIOMetadata.getAsTree(formatName). The Stream Metadata obtained from JPEGWriter throws an IllegalArgumentException saying standard metadata format name given above is unsupported. If it is not supported, then it should not have been returned by getMetadataFormatNames(). I also checked the return value of isStandardMetadataFormatSupported() and it is returning true. Hence the behaviour of getAsTree() and other methods are contradicting with each other.

      The documentation for getAsTree() claims that it will throw an IllegalArgException when the given format name is null or not one of the names returned by getMetadataFormatNames(). Both the conditions are not satisfied here and this method still throws IllegalArgException.

      I looked into the source code of JPEGMetadata.getAsTree(). It basically checks whether the current object is a stream metadata object. if so, it throws this exception for all the formats that are not native ones.

      This is reproducible on all platforms right from JDK1.4+.
      I have attached a sample code. Execute the sample code as follows.
      java WriterStreamMetadataTest <format>
      When you pass jpg as the format name, you will get the following exception:

      java.lang.IllegalArgumentException: Unsupported format name: javax_imageio_1.0
       at com.sun.imageio.plugins.jpeg.JPEGMetadata.getAsTree(JPEGMetadata.java:751)
       at WriterStreamMetadataTest.<init>(WriterStreamMetadataTest.java:46)
       at WriterStreamMetadataTest.main(WriterStreamMetadataTest.java:98)

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jdv Jayathirth D V
              Reporter:
              pmohansunw Praveen Mohan (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Imported:
                Indexed: