diff options
author | Roel Spilker <r.spilker@gmail.com> | 2016-10-17 22:24:04 +0200 |
---|---|---|
committer | Roel Spilker <r.spilker@gmail.com> | 2016-10-17 22:32:38 +0200 |
commit | 2f210869f3ad6608cfa1aa8b8beb12c2f4bb9c35 (patch) | |
tree | 3fabb722bd6bece123b2476f71e0e45ec5fe0658 | |
parent | 0f0cb68eac20c6f02b77c1fade88cdad8b7d85a2 (diff) | |
download | lombok-2f210869f3ad6608cfa1aa8b8beb12c2f4bb9c35.tar.gz lombok-2f210869f3ad6608cfa1aa8b8beb12c2f4bb9c35.tar.bz2 lombok-2f210869f3ad6608cfa1aa8b8beb12c2f4bb9c35.zip |
Make fieldsOfASTClasses thread safe
-rw-r--r-- | src/core/lombok/core/AST.java | 15 |
1 files changed, 8 insertions, 7 deletions
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<A extends AST<A, L, N>, L extends LombokNode<A, L, N>, } } - private static Map<Class<?>, Collection<FieldAccess>> fieldsOfASTClasses = new HashMap<Class<?>, Collection<FieldAccess>>(); + private static final ConcurrentMap<Class<?>, Collection<FieldAccess>> fieldsOfASTClasses = new ConcurrentHashMap<Class<?>, Collection<FieldAccess>>(); /** 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<FieldAccess> fieldsOf(Class<?> c) { Collection<FieldAccess> fields = fieldsOfASTClasses.get(c); @@ -221,8 +222,8 @@ public abstract class AST<A extends AST<A, L, N>, L extends LombokNode<A, L, N>, fields = new ArrayList<FieldAccess>(); getFields(c, fields); - fieldsOfASTClasses.put(c, fields); - return fields; + fieldsOfASTClasses.putIfAbsent(c, fields); + return fieldsOfASTClasses.get(c); } private void getFields(Class<?> c, Collection<FieldAccess> fields) { |