Skip to content

Commit 31957ae

Browse files
committed
more lyft fixes
Make an inner class static in ModelObject Fix a possible timing window in the ListedLicenseModelStore Signed-off-by: Gary O'Neall <[email protected]>
1 parent 9d34898 commit 31957ae

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/main/java/org/spdx/library/model/ModelObject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public abstract class ModelObject {
111111
// the following fields are for debugging when equivalent returns false
112112
enum NotEquivalent {
113113
DIFFERENT_CLASS, MISSING_PROPERTY, PROPERTY_NOT_EQUIVALENT, COMPARE_PROPERTY_MISSING};
114-
class NotEquivalentReason {
114+
static class NotEquivalentReason {
115115
NotEquivalent reason;
116116
String property = null;
117117

@@ -782,7 +782,7 @@ public boolean equivalent(ModelObject compare, boolean ignoreRelatedElements) th
782782
Optional<Object> propertyValue = this.getObjectPropertyValue(propertyName);
783783
if (propertyValue.isPresent()) {
784784
if (propertyValue.get() instanceof ModelCollection) {
785-
if (((ModelCollection<?>)(propertyValue.get())).size() > 0) {
785+
if (((ModelCollection<?>)propertyValue.get()).size() > 0) {
786786
lastNotEquivalentReason = new NotEquivalentReason(
787787
NotEquivalent.COMPARE_PROPERTY_MISSING, propertyName);
788788
return false;

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -833,14 +833,19 @@ public boolean isSpdxListedExceptionId(String listedLicenseDocumentUri, String e
833833

834834
@Override
835835
public Optional<TypedValue> getTypedValue(String documentUri, String id) throws InvalidSPDXAnalysisException {
836-
if (isSpdxListedLicenseId(documentUri, id)) {
837-
return Optional.of(new TypedValue(id, SpdxConstants.CLASS_SPDX_LISTED_LICENSE));
838-
} else if (isSpdxListedExceptionId(documentUri, id)) {
839-
return Optional.of(new TypedValue(id, SpdxConstants.CLASS_SPDX_LICENSE_EXCEPTION));
840-
} else if (crossRefs.containsKey(id)) {
841-
return Optional.of(new TypedValue(id, SpdxConstants.CLASS_CROSS_REF));
842-
} else {
843-
return Optional.empty();
836+
listedLicenseModificationLock.readLock().lock();
837+
try {
838+
if (licenseIds.containsKey(id.toLowerCase())) {
839+
return Optional.of(new TypedValue(id, SpdxConstants.CLASS_SPDX_LISTED_LICENSE));
840+
} else if (exceptionIds.containsKey(id.toLowerCase())) {
841+
return Optional.of(new TypedValue(id, SpdxConstants.CLASS_SPDX_LICENSE_EXCEPTION));
842+
} else if (crossRefs.containsKey(id)) {
843+
return Optional.of(new TypedValue(id, SpdxConstants.CLASS_CROSS_REF));
844+
} else {
845+
return Optional.empty();
846+
}
847+
} finally {
848+
listedLicenseModificationLock.readLock().unlock();
844849
}
845850
}
846851

0 commit comments

Comments
 (0)