diff --git a/android/guava/src/com/google/common/net/InternetDomainName.java b/android/guava/src/com/google/common/net/InternetDomainName.java index ba28e674793f..d098bf4fb0b9 100644 --- a/android/guava/src/com/google/common/net/InternetDomainName.java +++ b/android/guava/src/com/google/common/net/InternetDomainName.java @@ -27,6 +27,7 @@ import com.google.common.collect.ImmutableList; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.Immutable; +import com.google.errorprone.annotations.concurrent.LazyInit; import com.google.thirdparty.publicsuffix.PublicSuffixPatterns; import com.google.thirdparty.publicsuffix.PublicSuffixType; import java.util.List; @@ -126,6 +127,7 @@ public final class InternetDomainName { * value. */ @SuppressWarnings("Immutable") + @LazyInit private int publicSuffixIndexCache = SUFFIX_NOT_INITIALIZED; /** @@ -136,6 +138,7 @@ public final class InternetDomainName { * value. */ @SuppressWarnings("Immutable") + @LazyInit private int registrySuffixIndexCache = SUFFIX_NOT_INITIALIZED; /** Constructor used to implement {@link #from(String)}, and from subclasses. */ @@ -166,10 +169,12 @@ public final class InternetDomainName { * suffix was found. */ private int publicSuffixIndex() { - if (publicSuffixIndexCache == SUFFIX_NOT_INITIALIZED) { - publicSuffixIndexCache = findSuffixOfType(Optional.absent()); + int publicSuffixIndexLocal = publicSuffixIndexCache; + if (publicSuffixIndexLocal == SUFFIX_NOT_INITIALIZED) { + publicSuffixIndexCache = + publicSuffixIndexLocal = findSuffixOfType(Optional.absent()); } - return publicSuffixIndexCache; + return publicSuffixIndexLocal; } /** @@ -179,10 +184,12 @@ private int publicSuffixIndex() { * was found. */ private int registrySuffixIndex() { - if (registrySuffixIndexCache == SUFFIX_NOT_INITIALIZED) { - registrySuffixIndexCache = findSuffixOfType(Optional.of(PublicSuffixType.REGISTRY)); + int registrySuffixIndexLocal = registrySuffixIndexCache; + if (registrySuffixIndexLocal == SUFFIX_NOT_INITIALIZED) { + registrySuffixIndexCache = + registrySuffixIndexLocal = findSuffixOfType(Optional.of(PublicSuffixType.REGISTRY)); } - return registrySuffixIndexCache; + return registrySuffixIndexLocal; } /** diff --git a/guava/src/com/google/common/net/InternetDomainName.java b/guava/src/com/google/common/net/InternetDomainName.java index ba28e674793f..d098bf4fb0b9 100644 --- a/guava/src/com/google/common/net/InternetDomainName.java +++ b/guava/src/com/google/common/net/InternetDomainName.java @@ -27,6 +27,7 @@ import com.google.common.collect.ImmutableList; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.Immutable; +import com.google.errorprone.annotations.concurrent.LazyInit; import com.google.thirdparty.publicsuffix.PublicSuffixPatterns; import com.google.thirdparty.publicsuffix.PublicSuffixType; import java.util.List; @@ -126,6 +127,7 @@ public final class InternetDomainName { * value. */ @SuppressWarnings("Immutable") + @LazyInit private int publicSuffixIndexCache = SUFFIX_NOT_INITIALIZED; /** @@ -136,6 +138,7 @@ public final class InternetDomainName { * value. */ @SuppressWarnings("Immutable") + @LazyInit private int registrySuffixIndexCache = SUFFIX_NOT_INITIALIZED; /** Constructor used to implement {@link #from(String)}, and from subclasses. */ @@ -166,10 +169,12 @@ public final class InternetDomainName { * suffix was found. */ private int publicSuffixIndex() { - if (publicSuffixIndexCache == SUFFIX_NOT_INITIALIZED) { - publicSuffixIndexCache = findSuffixOfType(Optional.absent()); + int publicSuffixIndexLocal = publicSuffixIndexCache; + if (publicSuffixIndexLocal == SUFFIX_NOT_INITIALIZED) { + publicSuffixIndexCache = + publicSuffixIndexLocal = findSuffixOfType(Optional.absent()); } - return publicSuffixIndexCache; + return publicSuffixIndexLocal; } /** @@ -179,10 +184,12 @@ private int publicSuffixIndex() { * was found. */ private int registrySuffixIndex() { - if (registrySuffixIndexCache == SUFFIX_NOT_INITIALIZED) { - registrySuffixIndexCache = findSuffixOfType(Optional.of(PublicSuffixType.REGISTRY)); + int registrySuffixIndexLocal = registrySuffixIndexCache; + if (registrySuffixIndexLocal == SUFFIX_NOT_INITIALIZED) { + registrySuffixIndexCache = + registrySuffixIndexLocal = findSuffixOfType(Optional.of(PublicSuffixType.REGISTRY)); } - return registrySuffixIndexCache; + return registrySuffixIndexLocal; } /**