From 2f210869f3ad6608cfa1aa8b8beb12c2f4bb9c35 Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Mon, 17 Oct 2016 22:24:04 +0200 Subject: Make fieldsOfASTClasses thread safe --- src/core/lombok/core/AST.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/core/lombok/core/AST.java b/src/core/lombok/core/AST.java index e6efe058..2d5e5352 100644 --- a/src/core/lombok/core/AST.java +++ b/src/core/lombok/core/AST.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2013 The Project Lombok Authors. + * Copyright (C) 2009-2016 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -21,7 +21,7 @@ */ package lombok.core; -import static lombok.Lombok.*; +import static lombok.Lombok.sneakyThrow; import java.lang.reflect.Array; import java.lang.reflect.Field; @@ -31,10 +31,11 @@ import java.lang.reflect.Type; import java.net.URI; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.IdentityHashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import lombok.core.configuration.ConfigurationKey; import lombok.core.debug.HistogramTracker; @@ -209,11 +210,11 @@ public abstract class AST, L extends LombokNode, } } - private static Map, Collection> fieldsOfASTClasses = new HashMap, Collection>(); + private static final ConcurrentMap, Collection> fieldsOfASTClasses = new ConcurrentHashMap, Collection>(); /** Returns FieldAccess objects for the stated class. Each field that contains objects of the kind returned by * {@link #getStatementTypes()}, either directly or inside of an array or java.util.collection (or array-of-arrays, - * or collection-of-collections, etcetera), is returned. + * or collection-of-collections, et cetera), is returned. */ protected Collection fieldsOf(Class c) { Collection fields = fieldsOfASTClasses.get(c); @@ -221,8 +222,8 @@ public abstract class AST, L extends LombokNode, fields = new ArrayList(); getFields(c, fields); - fieldsOfASTClasses.put(c, fields); - return fields; + fieldsOfASTClasses.putIfAbsent(c, fields); + return fieldsOfASTClasses.get(c); } private void getFields(Class c, Collection fields) { -- cgit