File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed
protobuf/src/main/java/com/fasterxml/jackson/dataformat/protobuf Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 44import java .io .IOException ;
55import java .io .InputStream ;
66import java .net .URL ;
7+ import java .util .concurrent .locks .ReentrantLock ;
78
89import com .fasterxml .jackson .core .Version ;
910import com .fasterxml .jackson .core .type .TypeReference ;
@@ -42,7 +43,10 @@ public Builder(ProtobufMapper m) {
4243 *
4344 * @since 2.9
4445 */
45- protected DescriptorLoader _descriptorLoader ;
46+ protected volatile DescriptorLoader _descriptorLoader ;
47+
48+ // @since 2.18
49+ private final ReentrantLock _descriptorLock = new ReentrantLock ();
4650
4751 /*
4852 /**********************************************************
@@ -192,11 +196,19 @@ public FileDescriptorSet loadDescriptorSet(InputStream src) throws IOException {
192196 *
193197 * @since 2.9
194198 */
195- public synchronized DescriptorLoader descriptorLoader () throws IOException
199+ public DescriptorLoader descriptorLoader () throws IOException
196200 {
197201 DescriptorLoader l = _descriptorLoader ;
198202 if (l == null ) {
199- _descriptorLoader = l = DescriptorLoader .construct (this );
203+ _descriptorLock .lock ();
204+ try {
205+ l = _descriptorLoader ;
206+ if (l == null ) {
207+ _descriptorLoader = l = DescriptorLoader .construct (this );
208+ }
209+ } finally {
210+ _descriptorLock .unlock ();
211+ }
200212 }
201213 return l ;
202214 }
Original file line number Diff line number Diff line change @@ -319,3 +319,7 @@ Thomas de Lange (@thomasdelange5)
319319 * Contributed fix for #428 : (ion) `IonParser.getIntValue()` fails or does not handle
320320 value overflow checks
321321 (2.17 .0 )
322+
323+ PJ Fanning (pjfanning @github )
324+ * Contributed #484 : Rework synchronization in `ProtobufMapper`
325+ (2.18 .0 )
Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ Active maintainers:
1616
17172.18 .0 (not yet released )
1818
19- No changes since 2.17 .
19+ #484 : (protobuf ) Rework synchronization in `ProtobufMapper `
20+ (contributed by @pjfanning )
2021
21222.17 .0 (12 - Mar - 2024 )
2223
You can’t perform that action at this time.
0 commit comments