17
17
18
18
import java .util .ArrayList ;
19
19
import java .util .List ;
20
- import java .util .concurrent .atomic .AtomicBoolean ;
21
20
22
21
import org .springframework .beans .factory .InitializingBean ;
23
22
import org .springframework .data .convert .PropertyValueConverterFactories .ChainedPropertyValueConverterFactory ;
@@ -40,7 +39,7 @@ public class SimplePropertyValueConversions implements PropertyValueConversions,
40
39
private @ Nullable PropertyValueConverterFactory converterFactory ;
41
40
private @ Nullable ValueConverterRegistry <?> valueConverterRegistry ;
42
41
private boolean converterCacheEnabled = true ;
43
- private final AtomicBoolean initialized = new AtomicBoolean ( false ) ;
42
+ private boolean initialized = false ;
44
43
45
44
/**
46
45
* Set the {@link PropertyValueConverterFactory factory} responsible for creating the actual
@@ -92,7 +91,7 @@ public void setConverterCacheEnabled(boolean converterCacheEnabled) {
92
91
@ Override
93
92
public boolean hasValueConverter (PersistentProperty <?> property ) {
94
93
95
- if (!initialized . get () ) {
94
+ if (!initialized ) {
96
95
init ();
97
96
}
98
97
@@ -104,7 +103,7 @@ public boolean hasValueConverter(PersistentProperty<?> property) {
104
103
public <DV , SV , C extends PersistentProperty <C >, D extends ValueConversionContext <C >> PropertyValueConverter <DV , SV , D > getValueConverter (
105
104
C property ) {
106
105
107
- if (!initialized . get () ) {
106
+ if (!initialized ) {
108
107
init ();
109
108
}
110
109
@@ -114,29 +113,32 @@ public <DV, SV, C extends PersistentProperty<C>, D extends ValueConversionContex
114
113
/**
115
114
* May be called just once to initialize the underlying factory with its values.
116
115
*/
117
- public void init () {
116
+ public synchronized void init () {
118
117
119
- if (initialized .compareAndSet (false , true )) {
118
+ if (initialized ) {
119
+ return ;
120
+ }
120
121
121
- List <PropertyValueConverterFactory > factoryList = new ArrayList <>(3 );
122
+ List <PropertyValueConverterFactory > factoryList = new ArrayList <>(3 );
122
123
123
- if (converterFactory != null ) {
124
- factoryList .add (converterFactory );
125
- } else {
126
- factoryList .add (PropertyValueConverterFactory .simple ());
127
- }
124
+ if (converterFactory != null ) {
125
+ factoryList .add (converterFactory );
126
+ } else {
127
+ factoryList .add (PropertyValueConverterFactory .simple ());
128
+ }
128
129
129
- if ((valueConverterRegistry != null ) && !valueConverterRegistry .isEmpty ()) {
130
- factoryList .add (PropertyValueConverterFactory .configuredInstance (valueConverterRegistry ));
131
- }
130
+ if ((valueConverterRegistry != null ) && !valueConverterRegistry .isEmpty ()) {
131
+ factoryList .add (PropertyValueConverterFactory .configuredInstance (valueConverterRegistry ));
132
+ }
132
133
133
- PropertyValueConverterFactory targetFactory = factoryList .size () > 1
134
- ? PropertyValueConverterFactory .chained (factoryList )
135
- : factoryList .iterator ().next ();
134
+ PropertyValueConverterFactory targetFactory = factoryList .size () > 1
135
+ ? PropertyValueConverterFactory .chained (factoryList )
136
+ : factoryList .iterator ().next ();
136
137
137
- this .converterFactory = converterCacheEnabled ? PropertyValueConverterFactory .caching (targetFactory )
138
- : targetFactory ;
139
- }
138
+ this .converterFactory = converterCacheEnabled ? PropertyValueConverterFactory .caching (targetFactory )
139
+ : targetFactory ;
140
+
141
+ initialized = true ;
140
142
}
141
143
142
144
@ Override
0 commit comments