RFR: 8236987: Remove call to System.out.println from ImageIcon.loadImage

Tejesh R duke at openjdk.java.net
Mon Mar 21 13:59:45 UTC 2022


On Mon, 21 Mar 2022 13:19:14 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

>> How about setting the status to ABORTED only if it is Interrupted.....?
>> 
>>>             try {
>>>                 mTracker.waitForID(id, 0);
>>>             } catch (InterruptedException e) {
>>>                 bIsInterrupted = true;
>>>             }
>>>             if (bIsInterrupted == true)
>>>             {
>>>                 loadStatus = MediaTracker.ABORTED;
>>>             }
>>>             else
>>>             {
>>>                 loadStatus = mTracker.statusID(id, false);
>>>             }
>
> That's a good point. However, you have get the status from `MediaTracker` first: the image could finish loading before the thread was interrupted.
> 
> 
>         try {
>             mTracker.waitForID(id, 0);
>         } catch (InterruptedException e) {
>             interrupted = true;
>         }
> 
>         loadStatus = mTracker.statusID(id, false);
>         mTracker.removeImage(image, id);
>         if (interrupted && (loadStatus & MediaTracker.LOADING != 0)) {
>             loadStatus = MediaTracker.ABORTED;
>         }
> 
> 
> On the other hand, if the thread isn't interrupted, `waitForID` returns only after the image moves into its final state: `LOADED`, `ABORTED`, or `ERRORED`; if its status is still `LOADING`, the thread is interrupted.
> 
> Therefore my original suggestion is still correct: the status is amended only when the thread is interrupted. Yet the intention of the code seems clearer with the additional `interrupted` flag. At the same time, I'm still inclined towards the shorter version without the flag.

Yeah, I was also thinking about the load COMPLETE case...... sure then will update the same......

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

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



More information about the client-libs-dev mailing list