Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use write locks in license store to avoid deadlocks #251

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void create(TypedValue typedValue) throws InvalidSPDXAnalysisException {
@Override
public List<PropertyDescriptor> getPropertyValueDescriptors(String objectUri) throws InvalidSPDXAnalysisException {
String id = objectUriToId(objectUri);
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
LicenseJson license = fetchLicenseJson(licenseIds.get(id.toLowerCase()));
Expand All @@ -323,7 +323,7 @@ public List<PropertyDescriptor> getPropertyValueDescriptors(String objectUri) th
throw new SpdxIdNotFoundException("ID "+id+" is not a listed license ID. crossRef ID nor a listed exception ID");
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
}

Expand Down Expand Up @@ -479,7 +479,7 @@ public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Ob
boolean isLicenseId = false;
boolean isExceptionId = false;
CrossRefJson crossRef = null;
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
isLicenseId = true;
Expand All @@ -489,7 +489,7 @@ public void setValue(String objectUri, PropertyDescriptor propertyDescriptor, Ob
crossRef = crossRefs.get(id);
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
if (isLicenseId) {
LicenseJson license = fetchLicenseJson(id);
Expand Down Expand Up @@ -518,7 +518,7 @@ public void clearValueCollection(String objectUri, PropertyDescriptor propertyDe
boolean isLicenseId = false;
boolean isExceptionId = false;
CrossRefJson crossRef = null;
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
isLicenseId = true;
Expand All @@ -528,7 +528,7 @@ public void clearValueCollection(String objectUri, PropertyDescriptor propertyDe
crossRef = crossRefs.get(id);
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
if (isLicenseId) {
LicenseJson license = fetchLicenseJson(id);
Expand Down Expand Up @@ -557,7 +557,7 @@ public boolean addValueToCollection(String objectUri, PropertyDescriptor propert
boolean isLicenseId = false;
boolean isExceptionId = false;
CrossRefJson crossRef = null;
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
isLicenseId = true;
Expand All @@ -567,7 +567,7 @@ public boolean addValueToCollection(String objectUri, PropertyDescriptor propert
crossRef = crossRefs.get(id);
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
if (isLicenseId) {
LicenseJson license = fetchLicenseJson(id);
Expand Down Expand Up @@ -614,7 +614,7 @@ public boolean removeValueFromCollection(String objectUri, PropertyDescriptor pr
boolean isLicenseId = false;
boolean isExceptionId = false;
CrossRefJson crossRef = null;
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
isLicenseId = true;
Expand All @@ -624,7 +624,7 @@ public boolean removeValueFromCollection(String objectUri, PropertyDescriptor pr
crossRef = crossRefs.get(id);
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
if (isLicenseId) {
LicenseJson license = fetchLicenseJson(id);
Expand Down Expand Up @@ -674,7 +674,7 @@ public Iterator<Object> listValues(String objectUri, PropertyDescriptor property
boolean isLicenseId = false;
boolean isExceptionId = false;
CrossRefJson crossRef = null;
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
isLicenseId = true;
Expand All @@ -684,7 +684,7 @@ public Iterator<Object> listValues(String objectUri, PropertyDescriptor property
crossRef = crossRefs.get(id);
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
if (isLicenseId) {
LicenseJson license = fetchLicenseJson(id);
Expand Down Expand Up @@ -760,7 +760,7 @@ public Optional<Object> getValue(String objectUri, PropertyDescriptor propertyDe
boolean isLicenseId = false;
boolean isExceptionId = false;
CrossRefJson crossRef = null;
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
isLicenseId = true;
Expand All @@ -770,7 +770,7 @@ public Optional<Object> getValue(String objectUri, PropertyDescriptor propertyDe
crossRef = crossRefs.get(id);
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
if (SpdxConstantsV3.PROP_CREATION_INFO.equals(propertyDescriptor) && (isLicenseId || isExceptionId)) {
return Optional.of(licenseCreationInfo.getTypedValue());
Expand Down Expand Up @@ -888,7 +888,7 @@ public Optional<TypedValue> getTypedValue(String objectUri) throws InvalidSPDXAn
//NOTE: We only return the SPDX 3.0 version of the typed value, SPDX 2.X versions are also supported
// but there is no API to specify the version of the typedValue
String id = objectUriToId(objectUri);
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
return Optional.of(new TypedValue(objectUri, SpdxConstantsV3.EXPANDED_LICENSING_LISTED_LICENSE, SpdxConstantsV3.MODEL_SPEC_VERSION));
Expand All @@ -905,7 +905,7 @@ public Optional<TypedValue> getTypedValue(String objectUri) throws InvalidSPDXAn
return Optional.empty();
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
}

Expand All @@ -915,7 +915,7 @@ public void removeProperty(String objectUri, PropertyDescriptor propertyDescript
boolean isLicenseId = false;
boolean isExceptionId = false;
CrossRefJson crossRef = null;
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
isLicenseId = true;
Expand All @@ -925,7 +925,7 @@ public void removeProperty(String objectUri, PropertyDescriptor propertyDescript
crossRef = crossRefs.get(id);
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
if (isLicenseId) {
LicenseJson license = fetchLicenseJson(id);
Expand All @@ -949,7 +949,7 @@ public void removeProperty(String objectUri, PropertyDescriptor propertyDescript
public Stream<TypedValue> getAllItems(String documentUri, @Nullable String typeFilter)
throws InvalidSPDXAnalysisException {
Objects.requireNonNull(typeFilter, "Type filter can not be null");
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
List<TypedValue> allItems = new ArrayList<TypedValue>();
if (SpdxConstantsCompatV2.CLASS_SPDX_LISTED_LICENSE.equals(typeFilter)) {
Expand Down Expand Up @@ -985,7 +985,7 @@ public Stream<TypedValue> getAllItems(String documentUri, @Nullable String typeF
}
return Collections.unmodifiableList(allItems).stream();
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
}

Expand All @@ -998,7 +998,7 @@ public int collectionSize(String objectUri, PropertyDescriptor propertyDescripto
boolean isLicenseId = false;
boolean isExceptionId = false;
CrossRefJson crossRef = null;
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
isLicenseId = true;
Expand All @@ -1008,7 +1008,7 @@ public int collectionSize(String objectUri, PropertyDescriptor propertyDescripto
crossRef = crossRefs.get(id);
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
if (isLicenseId) {
LicenseJson license = fetchLicenseJson(id);
Expand Down Expand Up @@ -1036,7 +1036,7 @@ public boolean collectionContains(String objectUri, PropertyDescriptor propertyD
boolean isLicenseId = false;
boolean isExceptionId = false;
CrossRefJson crossRef = null;
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
isLicenseId = true;
Expand All @@ -1046,7 +1046,7 @@ public boolean collectionContains(String objectUri, PropertyDescriptor propertyD
crossRef = crossRefs.get(id);
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
if (isLicenseId) {
LicenseJson license = fetchLicenseJson(id);
Expand Down Expand Up @@ -1083,7 +1083,7 @@ public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescrip
boolean isLicenseId = false;
boolean isExceptionId = false;
CrossRefJson crossRef = null;
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
isLicenseId = true;
Expand All @@ -1093,7 +1093,7 @@ public boolean isCollectionMembersAssignableTo(String objectUri, PropertyDescrip
crossRef = crossRefs.get(id);
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
if (isLicenseId) {
LicenseJson license = fetchLicenseJson(id);
Expand Down Expand Up @@ -1121,7 +1121,7 @@ public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor
boolean isLicenseId = false;
boolean isExceptionId = false;
CrossRefJson crossRef = null;
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
isLicenseId = true;
Expand All @@ -1131,7 +1131,7 @@ public boolean isPropertyValueAssignableTo(String objectUri, PropertyDescriptor
crossRef = crossRefs.get(id);
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
if (isLicenseId) {
LicenseJson license = fetchLicenseJson(id);
Expand All @@ -1158,7 +1158,7 @@ public boolean isCollectionProperty(String objectUri, PropertyDescriptor propert
boolean isLicenseId = false;
boolean isExceptionId = false;
CrossRefJson crossRef = null;
listedLicenseModificationLock.readLock().lock();
listedLicenseModificationLock.writeLock().lock();
try {
if (licenseIds.containsKey(id.toLowerCase())) {
isLicenseId = true;
Expand All @@ -1168,7 +1168,7 @@ public boolean isCollectionProperty(String objectUri, PropertyDescriptor propert
crossRef = crossRefs.get(id);
}
} finally {
listedLicenseModificationLock.readLock().unlock();
listedLicenseModificationLock.writeLock().unlock();
}
if (isLicenseId) {
LicenseJson license = fetchLicenseJson(id);
Expand Down
Loading