9898 * needs, ie avoided providing classes loaded via a "shared" classloader.</p>
9999 *
100100 * @param <T> the type of data stored in an instance
101- * @see java.lang. Thread#getContextClassLoader
101+ * @see Thread#getContextClassLoader
102102 */
103103public class ContextClassLoaderLocal <T > {
104104 private final Map <ClassLoader , T > valueByClassLoader = new WeakHashMap <>();
@@ -121,31 +121,25 @@ public synchronized T get() {
121121 // synchronizing the whole method is a bit slower
122122 // but guarantees no subtle threading problems, and there's no
123123 // need to synchronize valueByClassLoader
124-
125124 // make sure that the map is given a change to purge itself
126125 valueByClassLoader .isEmpty ();
127126 try {
128-
129127 final ClassLoader contextClassLoader = Thread .currentThread ().getContextClassLoader ();
130128 if (contextClassLoader != null ) {
131-
132129 T value = valueByClassLoader .get (contextClassLoader );
133- if (value == null
134- && !valueByClassLoader .containsKey (contextClassLoader )) {
130+ if (value == null && !valueByClassLoader .containsKey (contextClassLoader )) {
135131 value = initialValue ();
136132 valueByClassLoader .put (contextClassLoader , value );
137133 }
138134 return value ;
139-
140135 }
141-
142- } catch (final SecurityException e ) { /* SWALLOW - should we log this? */ }
143-
136+ } catch (final SecurityException e ) {
137+ /* SWALLOW - should we log this? */ }
144138 // if none or exception, return the globalValue
145139 if (!globalValueInitialized ) {
146140 globalValue = initialValue ();
147141 globalValueInitialized = true ;
148- }// else already set
142+ } // else already set
149143 return globalValue ;
150144 }
151145
@@ -175,19 +169,16 @@ protected T initialValue() {
175169 public synchronized void set (final T value ) {
176170 // synchronizing the whole method is a bit slower
177171 // but guarentees no subtle threading problems
178-
179172 // make sure that the map is given a change to purge itself
180173 valueByClassLoader .isEmpty ();
181174 try {
182-
183175 final ClassLoader contextClassLoader = Thread .currentThread ().getContextClassLoader ();
184176 if (contextClassLoader != null ) {
185177 valueByClassLoader .put (contextClassLoader , value );
186178 return ;
187179 }
188-
189- } catch (final SecurityException e ) { /* SWALLOW - should we log this? */ }
190-
180+ } catch (final SecurityException e ) {
181+ /* SWALLOW - should we log this? */ }
191182 // if in doubt, set the global value
192183 globalValue = value ;
193184 globalValueInitialized = true ;
@@ -198,11 +189,10 @@ public synchronized void set(final T value) {
198189 */
199190 public synchronized void unset () {
200191 try {
201-
202192 final ClassLoader contextClassLoader = Thread .currentThread ().getContextClassLoader ();
203193 unset (contextClassLoader );
204-
205- } catch ( final SecurityException e ) { /* SWALLOW - should we log this? */ }
194+ } catch ( final SecurityException e ) {
195+ /* SWALLOW - should we log this? */ }
206196 }
207197
208198 /**
0 commit comments