Skip to content

Commit

Permalink
Fix a NPE and result handling
Browse files Browse the repository at this point in the history
Related to MID-6228.
  • Loading branch information
mederly committed Sep 25, 2020
1 parent 34d658a commit a48ee58
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
Expand Up @@ -183,7 +183,9 @@ public static ResourceShadowDiscriminator fromResourceShadowDiscriminatorType(
kind, intent, bean.getTag(),
BooleanUtils.isTrue(bean.isTombstone()));
rsd.setObjectClass(bean.getObjectClassName());
rsd.setOrder(bean.getDiscriminatorOrder());
if (bean.getDiscriminatorOrder() != null) {
rsd.setOrder(bean.getDiscriminatorOrder());
}
return rsd;
}

Expand Down
Expand Up @@ -178,47 +178,53 @@ public boolean validateValue(String newValue, ValuePolicyType pp,

OperationResult result = parentResult.createSubresult(OPERATION_STRING_POLICY_VALIDATION);
result.addArbitraryObjectAsParam("policyName", pp.getName());
normalize(pp);
try {
normalize(pp);

if (newValue == null) {
newValue = "";
}

LimitationsType lims = pp.getStringPolicy().getLimitations();

testMinimalLength(newValue, lims, result, messages);
testMaximalLength(newValue, lims, result, messages);

testMinimalUniqueCharacters(newValue, lims, result, messages);
if (newValue == null) {
newValue = "";
}

testProhibitedValues(newValue, pp.getProhibitedValues(), originResolver, shortDesc, task, result, messages);
LimitationsType lims = pp.getStringPolicy().getLimitations();

// TODO: this needs to be determined from ValuePolicyType archetype
ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
testCheckExpression(newValue, lims, expressionProfile, originResolver, shortDesc, task, result, messages);
testMinimalLength(newValue, lims, result, messages);
testMaximalLength(newValue, lims, result, messages);

if (!lims.getLimit().isEmpty()) {
// check limitation
HashSet<String> validChars;
HashSet<String> allValidChars = new HashSet<>();
List<String> characters = StringPolicyUtils.stringTokenizer(newValue);
for (StringLimitType stringLimitationType : lims.getLimit()) {
OperationResult limitResult = new OperationResult("Tested limitation: " + stringLimitationType.getDescription());
testMinimalUniqueCharacters(newValue, lims, result, messages);

validChars = getValidCharacters(stringLimitationType.getCharacterClass(), pp);
int count = countValidCharacters(validChars, characters);
allValidChars.addAll(validChars);
testMinimalOccurrence(stringLimitationType, count, limitResult, messages);
testMaximalOccurrence(stringLimitationType, count, limitResult, messages);
testMustBeFirst(stringLimitationType, limitResult, messages, newValue, validChars);
testProhibitedValues(newValue, pp.getProhibitedValues(), originResolver, shortDesc, task, result, messages);

limitResult.computeStatus();
result.addSubresult(limitResult);
// TODO: this needs to be determined from ValuePolicyType archetype
ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
testCheckExpression(newValue, lims, expressionProfile, originResolver, shortDesc, task, result, messages);

if (!lims.getLimit().isEmpty()) {
// check limitation
HashSet<String> validChars;
HashSet<String> allValidChars = new HashSet<>();
List<String> characters = StringPolicyUtils.stringTokenizer(newValue);
for (StringLimitType stringLimitationType : lims.getLimit()) {
OperationResult limitResult = new OperationResult("Tested limitation: " + stringLimitationType.getDescription());

validChars = getValidCharacters(stringLimitationType.getCharacterClass(), pp);
int count = countValidCharacters(validChars, characters);
allValidChars.addAll(validChars);
testMinimalOccurrence(stringLimitationType, count, limitResult, messages);
testMaximalOccurrence(stringLimitationType, count, limitResult, messages);
testMustBeFirst(stringLimitationType, limitResult, messages, newValue, validChars);

limitResult.computeStatus();
result.addSubresult(limitResult);
}
testInvalidCharacters(characters, allValidChars, result, messages);
}
testInvalidCharacters(characters, allValidChars, result, messages);
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.computeStatusIfUnknown();
}

result.computeStatus();
if (!result.isSuccess() && !messages.isEmpty()) {
result.setUserFriendlyMessage(
new LocalizableMessageListBuilder()
Expand Down

0 comments on commit a48ee58

Please sign in to comment.