On Mon, 21 Mar 2022 04:10:48 GMT, Tejesh R <d...@openjdk.java.net> wrote:
>>> N for current bug, where to change to change the status to >>> "ABORTED"......?? As I cannot change in ImageIcon class...... >> >> Why can't you change the status in `ImageIcon`? It's where you change it. >> >> >> loadStatus = mTracker.statusID(id, false); >> mTracker.removeImage(image, id); >> if (loadStatus & MediaTracker.LOADING != 0) { >> loadStatus = MediaTracker.ABORTED; >> } >> >> The first two lines already exist, right after the catching >> `InterruptedException`. You just need to add the `if` block to amend the >> status. > > 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. ------------- PR: https://git.openjdk.java.net/jdk/pull/7754