Abacn commented on code in PR #35752:
URL: https://github.com/apache/beam/pull/35752#discussion_r2246162127


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/CachingFactory.java:
##########
@@ -36,7 +36,7 @@
  * inner factory, so the schema comparison only need happen on the first 
lookup.
  */
 public class CachingFactory<CreatedT extends @NonNull Object> implements 
Factory<CreatedT> {
-  private transient @Nullable ConcurrentHashMap<TypeDescriptor<?>, CreatedT> 
cache = null;

Review Comment:
   it seems cache is "MonotonicNonNull" as well



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/CachingFactory.java:
##########
@@ -45,10 +45,16 @@ public CachingFactory(@UnknownInitialization 
Factory<CreatedT> innerFactory) {
   }
 
   private ConcurrentHashMap<TypeDescriptor<?>, CreatedT> getCache() {
-    if (cache == null) {
-      cache = new ConcurrentHashMap<>();
+    ConcurrentHashMap<TypeDescriptor<?>, CreatedT> value = cache;
+    if (value == null) {

Review Comment:
   it seems to me a temporary variable isn't necessary. One can just write
   
   ```
   if (cache == null) {
     synchronized (this) {
       if (cache == null) {cache =  new ConcurrentHashMap<>();}
     }
   }
   return cache;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@beam.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to