mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 08:18:29 +00:00
Make fieldsOfASTClasses thread safe
This commit is contained in:
1 parent
0f0cb68eac
commit
2f210869f3
1 file changed
+8
-7
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user