JDK-5033278 : difficulty adding text metadata to a JPEG image
  • 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: 2004-04-16
  • Updated: 2015-11-03
Related Reports
Relates :  
Description
There was an issue mentioned on the java-imageio-interest list about adding
text metadata to a JPEG image.  According to the submitter:

'It still throws the following exception at the point where the saved metadata
is accessed:  "JFIF APP0 must be first marker after SOI".'

(See attached testcase MetadataCreator.java...)

A follow-up on the java-imageio-interest list points out the problems with the
current spec:

I have just read the JPEG Metadata spec again, and [the submitter] is right. The
JPEG Metadata object is supposed to be able to correctly merge in a new
text node via the standard format.  Unfortunately, he has found a bug (a
spec bug, no less) in the JPEG Metadata handling.  The doc says:

>>setFromTree - Standard Format
>>The setFromTree operation, when given a tree in the standard  format,
>>performs a reset followed by a merge of the new tree.

and

>>mergeTree - Standard Format
>>The mergeTree operation, when given a tree in the standard  format, will
>>modify the native tree in the following ways:
>>...
>>Text - Each uncompressed text item is converted to a com node and
>>inserted according to the rules above for         merging com nodes.

and

>>com
>>A new com node is created and inserted as follows:
>>If there already exist com nodes, the new one is                inserted
>>after the last one.
>>If there are no com nodes, the new com node is inserted after the
>>app14Adobe node, if there is one.
>>If there is no app14Adobe node, the new com node is inserted at the
>>beginning of the                sequence.

What all of this amounts to is that if a Text node is added it will be
placed at the front of the sequence of markers, which is illegal for
JFIF.  The above spec, and the behavior, should be changed to state that
if a JFIF header is to be written, then the new com node is added after
it, not first in the sequence.

Comments
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)
18-03-2014

EVALUATION Not for Tiger. ###@###.### 2004-04-16
16-04-2004