JDK-4896304 : PNGMetadata.mergeTree throws exception when node returned by getAsTree is merged
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2003-07-25
  • Updated: 2015-11-03
Related Reports
Relates :  
Description
I am getting the ImageMetadata from PNG Reader and getting the XML DOM tree from the metadata using getAsTree() method for the standard format. I am trying to call mergeTree() method of this metadata object passing the same tree what i got from getAsTree() and format as standard metadata format. It is throwing an InvalidTreeException saying required attribute 'language' not present.
This seems to be reproducible only for some images and not for all PNG images and only for standard metadata format. This works fine for native format. 

This is reproducible on all platforms right from JDK1.4. 

I have attached the code and the image. Run it as follows.
java ReaderImageMetadataTest cup.png
You will get the IIOInvalidTreeException. Also try with another image sc0.png and this will work properly.

Here is the exception:
javax.imageio.metadata.IIOInvalidTreeException: Required attribute language not present!
 at com.sun.imageio.plugins.png.PNGMetadata.fatal(PNGMetadata.java:1076)
 at com.sun.imageio.plugins.png.PNGMetadata.getAttribute(PNGMetadata.java:1199)
 at com.sun.imageio.plugins.png.PNGMetadata.getAttribute(PNGMetadata.java:1208)
 at com.sun.imageio.plugins.png.PNGMetadata.mergeStandardTree(PNGMetadata.java:1913)
 at com.sun.imageio.plugins.png.PNGMetadata.mergeTree(PNGMetadata.java:1223)
 at ReaderImageMetadataTest.<init>(ReaderImageMetadataTest.java:60)
 at ReaderImageMetadataTest.main(ReaderImageMetadataTest.java:117)