When an IOException occurred: the PNGImageDecoder could notify ImageObservers
and ImageConsumers that it finished reading an image successfully. It should
instead report an error.
The original ticket discussed ImageObservers. I also addressed ImageConsumers
in the attached test, because that is how I originally noticed this problem.
The attached test creates a valid PNG, and then creates a ToolkitImage that
reads only 1/3 of it. This should result in an error.
## The Problem
PNGImageDecoder was calling:
`imageComplete(ImageConsumer.IMAGEERROR|ImageConsumer.STATICIMAGEDONE, true);`
We can't OR together image completion constants. In this case we're evaluating
`1|3`, which evaluates to `3`, so consumers were being notified of a
`STATICIMAGEDONE` completion. (We can OR together *hint constants*, so that's
probably what the original authors were thinking of.)
## Proposal
Remove this invocation of `imageComplete` entirely. When PNGImageDecoder throws
the IOException, a caller catches it and fires its own
`imageComplete(IMAGEERROR)` notification.
This is consistent with how JPEGImageDecoder is already implemented:
public void produceImage() throws IOException, ImageFormatException {
try {
readImage(input, new byte[1024]);
if (!aborted) {
imageComplete(ImageConsumer.STATICIMAGEDONE, true);
}
} catch (IOException e) {
if (!aborted) {
throw e;
}
} finally {
close();
}
}
## Simpler Alternative
In an early draft I tried keeping the notification, but removing the bad OR:
`imageComplete(ImageConsumer.IMAGEERROR, true);`
This resolved the main problem. But this resulted in two calls to
`imageComplete(IMAGEERROR)`. (One from PNGImageDecoder, and another from its
caller.)
The ImageConsumer contract doesn't forbid redundant errors (and it encourages
consumers to detach after `imageComplete` is called), but IMO a redundant error
message is not ideal.
If any reviewers want I can switch back to this approach instead.
---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK
Interim AI Policy](https://openjdk.org/legal/ai).
-------------
Commit messages:
- 6968794: rewiring test
- 6968794: don't call imageComplete() here
- 6968794: flag redundant imageComplete as failure
- 6968794: small code review nits
- 6968794: adding reachabilityFence
- 6968794: fix imageComplete(k) call
- 6968794: add comment about dimensions
- 6968794: first draft of failing unit test
- Merge remote-tracking branch 'origin/master'
- 8395707: fixing mistaken commit
- ... and 4 more: https://git.openjdk.org/jdk/compare/78bf06f4...e56ed90f
Changes: https://git.openjdk.org/jdk/pull/34017/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=34017&range=00
Issue: https://bugs.openjdk.org/browse/JDK-6968794
Stats: 241 lines in 2 files changed: 240 ins; 1 del; 0 mod
Patch: https://git.openjdk.org/jdk/pull/34017.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/34017/head:pull/34017
PR: https://git.openjdk.org/jdk/pull/34017