RFR: 8304818: Prune HttpURLConnection cache when corresponding Authenticator is garbage collected [v8]

Jaikiran Pai jpai at openjdk.org
Wed Apr 12 10:07:37 UTC 2023


On Wed, 12 Apr 2023 07:53:28 GMT, Michael McMahon <michaelm at openjdk.org> wrote:

>> Hi,
>> 
>> Can I get a review for this please? This change uses a Cleaner to check when java.net.Authenticator instances become unreachable, and then prunes the authentication cache for entries that correspond to that Authenticator and therefore cannot be used again. This stops the authentication cache from growing in size unbounded. Note, this only happens in the probably unusual case where more than one Authenticator object is used. Normally there is no reason to use more than one instance.
>> 
>> Thanks,
>> Michael.
>
> 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/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.

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?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13159#discussion_r1163909705
PR Review Comment: https://git.openjdk.org/jdk/pull/13159#discussion_r1163913890


More information about the net-dev mailing list