Skip to content

Commit c62c82d

Browse files
committed
8376420: Remove AppContext from javax/swing/ImageIcon.java
Reviewed-by: aivanov, psadhukhan
1 parent 9ef98a5 commit c62c82d

File tree

1 file changed

+5
-31
lines changed

1 file changed

+5
-31
lines changed

src/java.desktop/share/classes/javax/swing/ImageIcon.java

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -54,7 +54,6 @@
5454
import javax.accessibility.AccessibleStateSet;
5555

5656
import sun.awt.AWTAccessor;
57-
import sun.awt.AppContext;
5857

5958
/**
6059
* An implementation of the Icon interface that paints Icons
@@ -110,18 +109,7 @@ public class ImageIcon implements Icon, Serializable, Accessible {
110109
* @deprecated since 1.8
111110
*/
112111
@Deprecated
113-
protected static final Component component = createComponent();
114-
115-
private static final Component createComponent() {
116-
try {
117-
Component component = new Component() {};
118-
// 6482575 - clear the appContext field so as not to leak it
119-
AWTAccessor.getComponentAccessor().setAppContext(component, null);
120-
return component;
121-
} catch (Throwable t) {
122-
return null;
123-
}
124-
}
112+
protected static final Component component = new Component() {};
125113

126114
/**
127115
* Do not use this shared media tracker, which is used to load images.
@@ -136,8 +124,6 @@ private static final Component createComponent() {
136124
*/
137125
private static int mediaTrackerID;
138126

139-
private static final Object TRACKER_KEY = new StringBuilder("TRACKER_KEY");
140-
141127
int width = -1;
142128
int height = -1;
143129

@@ -346,24 +332,12 @@ private int getNextID() {
346332
}
347333
}
348334

335+
private static final MediaTracker MEDIA_TRACKER = new MediaTracker(new Component() {});
349336
/**
350-
* Returns the MediaTracker for the current AppContext, creating a new
351-
* MediaTracker if necessary.
337+
* Returns the shared MediaTracker.
352338
*/
353339
private MediaTracker getTracker() {
354-
Object trackerObj;
355-
AppContext ac = AppContext.getAppContext();
356-
// Opt: Only synchronize if trackerObj comes back null?
357-
// If null, synchronize, re-check for null, and put new tracker
358-
synchronized(ac) {
359-
trackerObj = ac.get(TRACKER_KEY);
360-
if (trackerObj == null) {
361-
Component comp = new Component() {};
362-
trackerObj = new MediaTracker(comp);
363-
ac.put(TRACKER_KEY, trackerObj);
364-
}
365-
}
366-
return (MediaTracker) trackerObj;
340+
return MEDIA_TRACKER;
367341
}
368342

369343
/**

0 commit comments

Comments
 (0)