RFR: 8304818: Prune HttpURLConnection cache when corresponding Authenticator is garbage collected [v8]
Michael McMahon
michaelm at openjdk.org
Wed Apr 12 10:56:38 UTC 2023
On Wed, 12 Apr 2023 09:52:09 GMT, Jaikiran Pai <jpai at openjdk.org> wrote:
>> Michael McMahon has updated the pull request incrementally with one additional commit since the last revision:
>>
>> update to remove dependency on AuthCacheImpl in j.n.Authenticator
>
> src/java.base/share/classes/sun/net/www/protocol/http/AuthCacheValue.java line 47:
>
>> 45: * The default authentication cache
>> 46: */
>> 47: protected static AuthCacheImpl defCache = new AuthCacheImpl();
>
> Do instances of `AuthCacheValue` get used concurrently (by different threads)? If so, should this `defCache` value be a `volatile`?
I think it can be made `final`. The method that sets the field is redundant and no longer used afaik.
> src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java line 217:
>
>> 215:
>> 216: /** A cache to obtain credentials from if the default cache not to be used */
>> 217: transient AuthCacheImpl authcache; // may be null
>
> Now that `AuthCacheValue` is no longer `Serializable` in this PR (and thus this `AuthenticationInfo` too isn't serializable), is the use of `transient` here and on some other fields in this class, needed anymore?
Good point.
> src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java line 332:
>
>> 330: static AuthenticationInfo getAuth(String key, URL url, AuthCacheImpl authcache) {
>> 331: // use default cache if none supplied
>> 332: authcache = authcache == null ? defCache : authcache;
>
> Was this supposed to be a declaration and assignment to a local variable here or are we intentionally overwrting the static `authcache` field here?
>
> Same comment in a few other methods in this class.
It sets the local variable (which is intended). It doesn't override the field. But, I agree it's confusing because of the name clash. I had changed a number of occurrences of this, but also missed a few. I will rename the local parameter variable.
> src/java.base/share/classes/sun/net/www/protocol/http/AuthenticationInfo.java line 382:
>
>> 380: String key = cacheKey(true);
>> 381: if (useAuthCache()) {
>> 382: authcache.put(key, this);
>
> Given that `authcache` can be null, do we need null checks in this and `removeFromCache()` method?
Actually, the comment attached to the field is wrong. It really means the parameter to the constructor can be null, in which case we set the field to the default cache. So, the field can not be null.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13159#discussion_r1163956609
PR Review Comment: https://git.openjdk.org/jdk/pull/13159#discussion_r1163957679
PR Review Comment: https://git.openjdk.org/jdk/pull/13159#discussion_r1163960747
PR Review Comment: https://git.openjdk.org/jdk/pull/13159#discussion_r1163965233
More information about the net-dev
mailing list