JDK-4954326 : JPGWriter.getDefaultImageMetadata throws internal error when image type is null
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 1.4.0,5.0,6u23,7,8,9,10,11,12,13,14
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2003-11-14
  • Updated: 2023-07-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
The API doc for ImageWriter.getDefaultImageMetadata() does not really specify what is the consequence of passing a null value for the image type parameter. JPG Writer throws an Internal Error where as other image formats throws a NPE when imagetype parameter is null. This has to be made consistant. All metadata related methods in ImageReader specify that an IllegalArgException would be thrown for such circumstances and it can be done for ImageWriter also. Though NULL is not a valid value, it would be better to throw some exception instead of throwing an Internal Error. 

Since the output of this method depends on this input value, it must be documented precisely saying an IllegalArgException will be thrown if the image type parameter is null so as to define the dependency of this API on the input value. 

This is reproducible on all platforms since JDK1.4.

I have attached a sample testcase. Execute the sample testcase and you would notice the following internal error:
Exception in thread "main" java.lang.InternalError: Default image metadata is inconsistent
at com.sun.imageio.plugins.jpeg.JPEGMetadata.<init>(JPEGMetadata.java:615)
at com.sun.imageio.plugins.jpeg.JPEGImageWriter.getDefaultImageMetadata(JPEGImageWriter.java:185)
at WriterMetadataErrorTest.<init>(WriterMetadataErrorTest.java:21)
at WriterMetadataErrorTest.main(WriterMetadataErrorTest.java:33)

Comments
Test build: JDK11b23(CC-build(http://slc07hab.us.oracle.com/jdk_coverage/builds/11_23/jdk-11-instr_linux-x64_bin.tar.gz )) Platform :ubuntu18.04-x64 ute tool: tonga-4.0.2-rc2.jar Test case failed as the same issue: 2D_ImageIOTiger/WriterNullValueTest http://sc11152645.us.oracle.com:8080/evergreen/results/11/b23/2d-cc/auto/ubuntu18.04-x64/results-2d-run1/ResultDir/WriterNullValueTest/WriterNullValueTest.log
07-08-2018

RULE 2D_ImageIOTiger/WriterNullValueTest Exception java.lang.InternalError: Default image metadata is inconsistent RULE 2D_ImageIOTiger/WriterNullValueTest Exception java.lang.NullPointerException RULE 2D_ImageIOTiger/WriterNullValueTest ExitCode 255
25-11-2014

Please re-open if - if fix is in progress or on the plan to fix soon - if this is a P3 (file as P3, not P4)
14-03-2014

2D_ImageIOTiger/Testcase#WriterNullValueTest
23-11-2012