On Thu, 10 Mar 2022 15:59:26 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:

>> WaitForID() definition states that "If there is an error while loading or 
>> scaling an image, then that image is considered to have finished loading". 
>> Does this indicates that no error checking is required.....?
>
> But in this case it's the waiting thread that is interrupted. The 
> `MediaTracker` could complete loading the image successfully yet `ImageIcon` 
> instance wouldn't update its `loadStatus` because it removes itself from the 
> media tracker.

We shouldn't be setting any MediaTracker status here - this is the caller ! It 
would be absolutely wrong. And it seems likely to me that this println was put 
there by the developer of this code who was him/herself not sure if this would 
occur and what to do about it so wanted to have a message if it ever occurred 
so they could figure out how to handle it.
It seems to me that if the thread were interrupted there'd only be a very 
narrow window in which it likely that the image were complete and that if 
interrupted then I agree with what I think Alexey is saying which is that the 
MediaTracker may not have had a chance to even update status since it was 
interrupted .. depends how sophisticated the implementation is.
Since ImageIcon.getLoadStatus() specifies only 3 possible return values then 
yes, we should ensure it is one of those . So if it is LOADING then set it to 
ABORTED .. However a possible wrinkle is that this call being interrupted may 
not actually prevent the separate threads the MediaTracker kicks off from 
continuing .. so it may actually be still loading. And it is just that the 
waiting was interrupted.
Someone would need to dig into MediaTracker to check.
But since the code removes the image from the tracker .. maybe we don't care ?

-------------

PR: https://git.openjdk.java.net/jdk/pull/7754

Reply via email to