Skip to content

Commit f483016

Browse files
committed
Use write locks in license store to avoid deadlocks
Signed-off-by: Gary O'Neall <[email protected]>
1 parent 1353ae4 commit f483016

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

src/main/java/org/spdx/storage/listedlicense/SpdxListedLicenseModelStore.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public List<PropertyDescriptor> getPropertyValueDescriptors(String objectUri) th
309309
return LicenseCreatorAgent.ALL_PROPERTY_DESCRIPTORS;
310310
}
311311
String id = objectUriToId(objectUri);
312-
listedLicenseModificationLock.readLock().lock();
312+
listedLicenseModificationLock.writeLock().lock();
313313
try {
314314
if (licenseIds.containsKey(id.toLowerCase())) {
315315
LicenseJson license = fetchLicenseJson(licenseIds.get(id.toLowerCase()));
@@ -326,7 +326,7 @@ public List<PropertyDescriptor> getPropertyValueDescriptors(String objectUri) th
326326
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID. crossRef ID nor a listed exception ID");
327327
}
328328
} finally {
329-
listedLicenseModificationLock.readLock().unlock();
329+
listedLicenseModificationLock.writeLock().unlock();
330330
}
331331
}
332332

@@ -489,7 +489,7 @@ public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Ob
489489
boolean isLicenseId = false;
490490
boolean isExceptionId = false;
491491
CrossRefJson crossRef = null;
492-
listedLicenseModificationLock.readLock().lock();
492+
listedLicenseModificationLock.writeLock().lock();
493493
try {
494494
if (licenseIds.containsKey(id.toLowerCase())) {
495495
isLicenseId = true;
@@ -499,7 +499,7 @@ public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Ob
499499
crossRef = crossRefs.get(id);
500500
}
501501
} finally {
502-
listedLicenseModificationLock.readLock().unlock();
502+
listedLicenseModificationLock.writeLock().unlock();
503503
}
504504
if (isLicenseId) {
505505
LicenseJson license = fetchLicenseJson(id);
@@ -531,7 +531,7 @@ public void clearValueCollection(String objectUri, PropertyDescriptor propertyDe
531531
boolean isLicenseId = false;
532532
boolean isExceptionId = false;
533533
CrossRefJson crossRef = null;
534-
listedLicenseModificationLock.readLock().lock();
534+
listedLicenseModificationLock.writeLock().lock();
535535
try {
536536
if (licenseIds.containsKey(id.toLowerCase())) {
537537
isLicenseId = true;
@@ -541,7 +541,7 @@ public void clearValueCollection(String objectUri, PropertyDescriptor propertyDe
541541
crossRef = crossRefs.get(id);
542542
}
543543
} finally {
544-
listedLicenseModificationLock.readLock().unlock();
544+
listedLicenseModificationLock.writeLock().unlock();
545545
}
546546
if (isLicenseId) {
547547
LicenseJson license = fetchLicenseJson(id);
@@ -573,7 +573,7 @@ public boolean addValueToCollection(String objectUri, PropertyDescriptor propert
573573
boolean isLicenseId = false;
574574
boolean isExceptionId = false;
575575
CrossRefJson crossRef = null;
576-
listedLicenseModificationLock.readLock().lock();
576+
listedLicenseModificationLock.writeLock().lock();
577577
try {
578578
if (licenseIds.containsKey(id.toLowerCase())) {
579579
isLicenseId = true;
@@ -583,7 +583,7 @@ public boolean addValueToCollection(String objectUri, PropertyDescriptor propert
583583
crossRef = crossRefs.get(id);
584584
}
585585
} finally {
586-
listedLicenseModificationLock.readLock().unlock();
586+
listedLicenseModificationLock.writeLock().unlock();
587587
}
588588
if (isLicenseId) {
589589
LicenseJson license = fetchLicenseJson(id);
@@ -631,7 +631,7 @@ public boolean removeValueFromCollection(String objectUri, PropertyDescriptor pr
631631
boolean isLicenseId = false;
632632
boolean isExceptionId = false;
633633
CrossRefJson crossRef = null;
634-
listedLicenseModificationLock.readLock().lock();
634+
listedLicenseModificationLock.writeLock().lock();
635635
try {
636636
if (licenseIds.containsKey(id.toLowerCase())) {
637637
isLicenseId = true;
@@ -641,7 +641,7 @@ public boolean removeValueFromCollection(String objectUri, PropertyDescriptor pr
641641
crossRef = crossRefs.get(id);
642642
}
643643
} finally {
644-
listedLicenseModificationLock.readLock().unlock();
644+
listedLicenseModificationLock.writeLock().unlock();
645645
}
646646
if (isLicenseId) {
647647
LicenseJson license = fetchLicenseJson(id);
@@ -690,7 +690,7 @@ public Iterator<Object> listValues(String objectUri, PropertyDescriptor property
690690
boolean isLicenseId = false;
691691
boolean isExceptionId = false;
692692
CrossRefJson crossRef = null;
693-
listedLicenseModificationLock.readLock().lock();
693+
listedLicenseModificationLock.writeLock().lock();
694694
try {
695695
if (licenseIds.containsKey(id.toLowerCase())) {
696696
isLicenseId = true;
@@ -700,7 +700,7 @@ public Iterator<Object> listValues(String objectUri, PropertyDescriptor property
700700
crossRef = crossRefs.get(id);
701701
}
702702
} finally {
703-
listedLicenseModificationLock.readLock().unlock();
703+
listedLicenseModificationLock.writeLock().unlock();
704704
}
705705
if (isLicenseId) {
706706
LicenseJson license = fetchLicenseJson(id);
@@ -777,7 +777,7 @@ public Optional<Object> getValue(String objectUri, PropertyDescriptor propertyDe
777777
boolean isLicenseId = false;
778778
boolean isExceptionId = false;
779779
CrossRefJson crossRef = null;
780-
listedLicenseModificationLock.readLock().lock();
780+
listedLicenseModificationLock.writeLock().lock();
781781
try {
782782
if (licenseIds.containsKey(id.toLowerCase())) {
783783
isLicenseId = true;
@@ -787,7 +787,7 @@ public Optional<Object> getValue(String objectUri, PropertyDescriptor propertyDe
787787
crossRef = crossRefs.get(id);
788788
}
789789
} finally {
790-
listedLicenseModificationLock.readLock().unlock();
790+
listedLicenseModificationLock.writeLock().unlock();
791791
}
792792
if (SpdxConstantsV3.PROP_CREATION_INFO.equals(propertyDescriptor) && (isLicenseId || isExceptionId)) {
793793
return Optional.of(licenseCreationInfo.getTypedValue());
@@ -906,7 +906,7 @@ public Optional<TypedValue> getTypedValue(String objectUri) throws InvalidSPDXAn
906906
return Optional.of(licenseCreator.getTypedValue());
907907
}
908908
String id = objectUriToId(objectUri);
909-
listedLicenseModificationLock.readLock().lock();
909+
listedLicenseModificationLock.writeLock().lock();
910910
try {
911911
if (licenseIds.containsKey(id.toLowerCase())) {
912912
return Optional.of(new TypedValue(objectUri, SpdxConstantsV3.EXPANDED_LICENSING_LISTED_LICENSE, SpdxConstantsV3.MODEL_SPEC_VERSION));
@@ -919,7 +919,7 @@ public Optional<TypedValue> getTypedValue(String objectUri) throws InvalidSPDXAn
919919
return Optional.empty();
920920
}
921921
} finally {
922-
listedLicenseModificationLock.readLock().unlock();
922+
listedLicenseModificationLock.writeLock().unlock();
923923
}
924924
}
925925

@@ -936,7 +936,7 @@ public void removeProperty(String objectUri, PropertyDescriptor propertyDescript
936936
boolean isLicenseId = false;
937937
boolean isExceptionId = false;
938938
CrossRefJson crossRef = null;
939-
listedLicenseModificationLock.readLock().lock();
939+
listedLicenseModificationLock.writeLock().lock();
940940
try {
941941
if (licenseIds.containsKey(id.toLowerCase())) {
942942
isLicenseId = true;
@@ -946,7 +946,7 @@ public void removeProperty(String objectUri, PropertyDescriptor propertyDescript
946946
crossRef = crossRefs.get(id);
947947
}
948948
} finally {
949-
listedLicenseModificationLock.readLock().unlock();
949+
listedLicenseModificationLock.writeLock().unlock();
950950
}
951951
if (isLicenseId) {
952952
LicenseJson license = fetchLicenseJson(id);
@@ -966,7 +966,7 @@ public void removeProperty(String objectUri, PropertyDescriptor propertyDescript
966966
public Stream<TypedValue> getAllItems(String documentUri, @Nullable String typeFilter)
967967
throws InvalidSPDXAnalysisException {
968968
Objects.requireNonNull(typeFilter, "Type filter can not be null");
969-
listedLicenseModificationLock.readLock().lock();
969+
listedLicenseModificationLock.writeLock().lock();
970970
try {
971971
List<TypedValue> allItems = new ArrayList<TypedValue>();
972972
if (SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(typeFilter)) {
@@ -1002,7 +1002,7 @@ public Stream<TypedValue> getAllItems(String documentUri, @Nullable String typeF
10021002
}
10031003
return Collections.unmodifiableList(allItems).stream();
10041004
} finally {
1005-
listedLicenseModificationLock.readLock().unlock();
1005+
listedLicenseModificationLock.writeLock().unlock();
10061006
}
10071007
}
10081008

@@ -1020,7 +1020,7 @@ public int collectionSize(String objectUri, PropertyDescriptor propertyDescripto
10201020
boolean isLicenseId = false;
10211021
boolean isExceptionId = false;
10221022
CrossRefJson crossRef = null;
1023-
listedLicenseModificationLock.readLock().lock();
1023+
listedLicenseModificationLock.writeLock().lock();
10241024
try {
10251025
if (licenseIds.containsKey(id.toLowerCase())) {
10261026
isLicenseId = true;
@@ -1030,7 +1030,7 @@ public int collectionSize(String objectUri, PropertyDescriptor propertyDescripto
10301030
crossRef = crossRefs.get(id);
10311031
}
10321032
} finally {
1033-
listedLicenseModificationLock.readLock().unlock();
1033+
listedLicenseModificationLock.writeLock().unlock();
10341034
}
10351035
if (isLicenseId) {
10361036
LicenseJson license = fetchLicenseJson(id);
@@ -1059,7 +1059,7 @@ public boolean collectionContains(String objectUri, PropertyDescriptor propertyD
10591059
boolean isLicenseId = false;
10601060
boolean isExceptionId = false;
10611061
CrossRefJson crossRef = null;
1062-
listedLicenseModificationLock.readLock().lock();
1062+
listedLicenseModificationLock.writeLock().lock();
10631063
try {
10641064
if (licenseIds.containsKey(id.toLowerCase())) {
10651065
isLicenseId = true;
@@ -1069,7 +1069,7 @@ public boolean collectionContains(String objectUri, PropertyDescriptor propertyD
10691069
crossRef = crossRefs.get(id);
10701070
}
10711071
} finally {
1072-
listedLicenseModificationLock.readLock().unlock();
1072+
listedLicenseModificationLock.writeLock().unlock();
10731073
}
10741074
if (isLicenseId) {
10751075
LicenseJson license = fetchLicenseJson(id);
@@ -1107,7 +1107,7 @@ public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescrip
11071107
boolean isLicenseId = false;
11081108
boolean isExceptionId = false;
11091109
CrossRefJson crossRef = null;
1110-
listedLicenseModificationLock.readLock().lock();
1110+
listedLicenseModificationLock.writeLock().lock();
11111111
try {
11121112
if (licenseIds.containsKey(id.toLowerCase())) {
11131113
isLicenseId = true;
@@ -1117,7 +1117,7 @@ public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescrip
11171117
crossRef = crossRefs.get(id);
11181118
}
11191119
} finally {
1120-
listedLicenseModificationLock.readLock().unlock();
1120+
listedLicenseModificationLock.writeLock().unlock();
11211121
}
11221122
if (isLicenseId) {
11231123
LicenseJson license = fetchLicenseJson(id);
@@ -1146,7 +1146,7 @@ public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor
11461146
boolean isLicenseId = false;
11471147
boolean isExceptionId = false;
11481148
CrossRefJson crossRef = null;
1149-
listedLicenseModificationLock.readLock().lock();
1149+
listedLicenseModificationLock.writeLock().lock();
11501150
try {
11511151
if (licenseIds.containsKey(id.toLowerCase())) {
11521152
isLicenseId = true;
@@ -1156,7 +1156,7 @@ public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor
11561156
crossRef = crossRefs.get(id);
11571157
}
11581158
} finally {
1159-
listedLicenseModificationLock.readLock().unlock();
1159+
listedLicenseModificationLock.writeLock().unlock();
11601160
}
11611161
if (isLicenseId) {
11621162
LicenseJson license = fetchLicenseJson(id);
@@ -1184,7 +1184,7 @@ public boolean isCollectionProperty(String objectUri, PropertyDescriptor propert
11841184
boolean isLicenseId = false;
11851185
boolean isExceptionId = false;
11861186
CrossRefJson crossRef = null;
1187-
listedLicenseModificationLock.readLock().lock();
1187+
listedLicenseModificationLock.writeLock().lock();
11881188
try {
11891189
if (licenseIds.containsKey(id.toLowerCase())) {
11901190
isLicenseId = true;
@@ -1194,7 +1194,7 @@ public boolean isCollectionProperty(String objectUri, PropertyDescriptor propert
11941194
crossRef = crossRefs.get(id);
11951195
}
11961196
} finally {
1197-
listedLicenseModificationLock.readLock().unlock();
1197+
listedLicenseModificationLock.writeLock().unlock();
11981198
}
11991199
if (isLicenseId) {
12001200
LicenseJson license = fetchLicenseJson(id);

0 commit comments

Comments
 (0)