7u Code review request for 7033170, 7092821, 7092825

David Schlosnagle schlosna at gmail.com
Wed Jan 11 22:28:46 PST 2012


On Thu, Jan 12, 2012 at 12:48 AM, David Schlosnagle <schlosna at gmail.com> wrote:
>    private ConcurrentMap<ServiceKey,Service> getLookupCache() {
>        if (lookupCache == null) {
>            synchronized (this) {
>                // must fall back on double checked lock
>                if (lookupCache == null) {
>                    lookupCache = new ConcurrentHashMap<>();
>                }
>            }
>        }
>        return lookupCache;
>    }

Slight correction to the previous suggested getLookupCache() method as
there was still the possibility that when interleaved methods that set
lookupCache = null would result in getLookupCache() returning null and
trigger NPE in getService:

    private ConcurrentMap<ServiceKey,Service> getLookupCache() {
        ConcurrentMap<ServiceKey,Service> localLookupCache = lookupCache;
        if (localLookupCache == null) {
            // must fall back on double checked lock
            synchronized (this) {
                if (lookupCache == null) {
                    localLookupCache = new ConcurrentHashMap<>();
                    lookupCache = localLookupCache;
                }
            }
        }
        return localLookupCache;
    }


- Dave



More information about the security-dev mailing list