fix(metadata-io): remove assert in favor of exceptions (#8035)

This commit is contained in:
david-leifker 2023-05-18 16:46:14 -05:00 committed by GitHub
parent dc4a20301f
commit 820981072f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 48 additions and 10 deletions

View File

@ -55,7 +55,10 @@ public class Features {
@Nonnull
public static List<Features> merge(@Nonnull List<Features> featureList1, @Nonnull List<Features> featureList2) {
assert (featureList1.size() == featureList2.size());
if (featureList1.size() != featureList2.size()) {
throw new IllegalArgumentException(String.format("Expected both lists to have the same number of elements. %s != %s",
featureList1.size(), featureList2.size()));
}
return Streams.zip(featureList1.stream(), featureList2.stream(), Features::merge).collect(Collectors.toList());
}
}

View File

@ -413,7 +413,10 @@ public class TimelineServiceImpl implements TimelineService {
SemanticVersion curGroupVersion = null;
long transactionId = FIRST_TRANSACTION_ID - 1;
for (Map.Entry<Long, List<ChangeTransaction>> entry : changeTransactionsMap.entrySet()) {
assert (transactionId < entry.getKey());
if (transactionId >= entry.getKey()) {
throw new IllegalArgumentException(String.format("transactionId should be < previous. %s >= %s",
transactionId, entry.getKey()));
}
transactionId = entry.getKey();
SemanticChangeType highestChangeInGroup = SemanticChangeType.NONE;
ChangeTransaction highestChangeTransaction = entry.getValue().stream()

View File

@ -84,11 +84,16 @@ public class EditableDatasetPropertiesChangeEventGenerator
@Override
public ChangeTransaction getSemanticDiff(EntityAspect previousValue, EntityAspect currentValue,
ChangeCategory element, JsonPatch rawDiff, boolean rawDiffsRequested) {
if (currentValue == null) {
throw new IllegalArgumentException("EntityAspect currentValue should not be null");
}
if (!previousValue.getAspect().equals(EDITABLE_DATASET_PROPERTIES_ASPECT_NAME) || !currentValue.getAspect()
.equals(EDITABLE_DATASET_PROPERTIES_ASPECT_NAME)) {
throw new IllegalArgumentException("Aspect is not " + EDITABLE_DATASET_PROPERTIES_ASPECT_NAME);
}
assert (currentValue != null);
List<ChangeEvent> changeEvents = new ArrayList<>();
if (element == ChangeCategory.DOCUMENTATION) {
EditableDatasetProperties baseDatasetProperties = getEditableDatasetPropertiesFromAspect(previousValue);

View File

@ -221,11 +221,15 @@ public class EditableSchemaMetadataChangeEventGenerator extends EntityChangeEven
public ChangeTransaction getSemanticDiff(EntityAspect previousValue, EntityAspect currentValue,
ChangeCategory element, JsonPatch rawDiff, boolean rawDiffsRequested) {
if (currentValue == null) {
throw new IllegalArgumentException("EntityAspect currentValue should not be null");
}
if (!previousValue.getAspect().equals(EDITABLE_SCHEMA_METADATA_ASPECT_NAME) || !currentValue.getAspect()
.equals(EDITABLE_SCHEMA_METADATA_ASPECT_NAME)) {
throw new IllegalArgumentException("Aspect is not " + EDITABLE_SCHEMA_METADATA_ASPECT_NAME);
}
assert (currentValue != null);
EditableSchemaMetadata baseEditableSchemaMetadata = getEditableSchemaMetadataFromAspect(previousValue);
EditableSchemaMetadata targetEditableSchemaMetadata = getEditableSchemaMetadataFromAspect(currentValue);
List<ChangeEvent> changeEvents = new ArrayList<>();

View File

@ -133,11 +133,16 @@ public class GlossaryTermsChangeEventGenerator extends EntityChangeEventGenerato
@Override
public ChangeTransaction getSemanticDiff(EntityAspect previousValue, EntityAspect currentValue,
ChangeCategory element, JsonPatch rawDiff, boolean rawDiffsRequested) {
if (currentValue == null) {
throw new IllegalArgumentException("EntityAspect currentValue should not be null");
}
if (!previousValue.getAspect().equals(GLOSSARY_TERMS_ASPECT_NAME) || !currentValue.getAspect()
.equals(GLOSSARY_TERMS_ASPECT_NAME)) {
throw new IllegalArgumentException("Aspect is not " + GLOSSARY_TERMS_ASPECT_NAME);
}
assert (currentValue != null);
GlossaryTerms baseGlossaryTerms = getGlossaryTermsFromAspect(previousValue);
GlossaryTerms targetGlossaryTerms = getGlossaryTermsFromAspect(currentValue);
List<ChangeEvent> changeEvents = new ArrayList<>();

View File

@ -152,11 +152,16 @@ public class InstitutionalMemoryChangeEventGenerator extends EntityChangeEventGe
@Override
public ChangeTransaction getSemanticDiff(EntityAspect previousValue, EntityAspect currentValue,
ChangeCategory element, JsonPatch rawDiff, boolean rawDiffsRequested) {
if (currentValue == null) {
throw new IllegalArgumentException("EntityAspect currentValue should not be null");
}
if (!previousValue.getAspect().equals(INSTITUTIONAL_MEMORY_ASPECT_NAME) || !currentValue.getAspect()
.equals(INSTITUTIONAL_MEMORY_ASPECT_NAME)) {
throw new IllegalArgumentException("Aspect is not " + INSTITUTIONAL_MEMORY_ASPECT_NAME);
}
assert (currentValue != null);
InstitutionalMemory baseInstitutionalMemory = getInstitutionalMemoryFromAspect(previousValue);
InstitutionalMemory targetInstitutionalMemory = getInstitutionalMemoryFromAspect(currentValue);
List<ChangeEvent> changeEvents = new ArrayList<>();

View File

@ -147,11 +147,15 @@ public class OwnershipChangeEventGenerator extends EntityChangeEventGenerator<Ow
@Override
public ChangeTransaction getSemanticDiff(EntityAspect previousValue, EntityAspect currentValue,
ChangeCategory element, JsonPatch rawDiff, boolean rawDiffsRequested) {
if (currentValue == null) {
throw new IllegalArgumentException("EntityAspect currentValue should not be null");
}
if (!previousValue.getAspect().equals(OWNERSHIP_ASPECT_NAME) || !currentValue.getAspect()
.equals(OWNERSHIP_ASPECT_NAME)) {
throw new IllegalArgumentException("Aspect is not " + OWNERSHIP_ASPECT_NAME);
}
assert (currentValue != null);
Ownership baseOwnership = getOwnershipFromAspect(previousValue);
Ownership targetOwnership = getOwnershipFromAspect(currentValue);

View File

@ -298,7 +298,9 @@ public class SchemaMetadataChangeEventGenerator extends EntityChangeEventGenerat
}
private static void sortFieldsByPath(SchemaMetadata schemaMetadata) {
assert (schemaMetadata != null);
if (schemaMetadata == null) {
throw new IllegalArgumentException("SchemaMetadata should not be null");
}
List<SchemaField> schemaFields = new ArrayList<>(schemaMetadata.getFields());
schemaFields.sort(Comparator.comparing(SchemaField::getFieldPath));
schemaMetadata.setFields(new SchemaFieldArray(schemaFields));
@ -453,7 +455,11 @@ public class SchemaMetadataChangeEventGenerator extends EntityChangeEventGenerat
SchemaMetadata baseSchema = getSchemaMetadataFromAspect(previousValue);
SchemaMetadata targetSchema = getSchemaMetadataFromAspect(currentValue);
assert (targetSchema != null);
if (targetSchema == null) {
throw new IllegalStateException("SchemaMetadata targetSchema should not be null");
}
List<ChangeEvent> changeEvents;
try {
changeEvents = new ArrayList<>(

View File

@ -464,7 +464,10 @@ public class ESAggregatedStatsDAO {
// 3.1 Do a DFS of the aggregation tree and generate the rows.
rowGenHelper(filterAgg.getAggregations(), 0, groupingBuckets.length, rows, rowAcc,
ImmutableList.copyOf(groupingBuckets), ImmutableList.copyOf(aggregationSpecs), aspectSpec);
assert (rowAcc.isEmpty());
if (!rowAcc.isEmpty()) {
throw new IllegalStateException("Expected stack to be empty.");
}
resultTable.setRows(new StringArrayArray(rows));
return resultTable;