Skip to content

Commit

Permalink
Bugfix NPE in target percentage (#819)
Browse files Browse the repository at this point in the history
* Fixed NullPointerException in groups validation callback

Signed-off-by: Natalia Kislicyn <[email protected]>
  • Loading branch information
Nkyn authored and Jeroen Laverman committed Jun 6, 2019
1 parent fde0cbd commit 3b15e80
Showing 1 changed file with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.vaadin.data.Validator;
import com.vaadin.data.util.converter.StringToFloatConverter;
import com.vaadin.data.util.converter.StringToIntegerConverter;
import com.vaadin.data.validator.RangeValidator;
import com.vaadin.data.validator.FloatRangeValidator;
import com.vaadin.data.validator.IntegerRangeValidator;
import com.vaadin.server.FontAwesome;
Expand All @@ -62,6 +63,8 @@
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;

import static org.eclipse.hawkbit.ui.utils.HawkbitCommonUtil.getCurrentLocale;

/**
* Define groups for a Rollout
*/
Expand Down Expand Up @@ -331,22 +334,28 @@ private void setGroupsValidation(final RolloutGroupsValidation validation) {
}

// validate the single groups
final int maxTargets = quotaManagement.getMaxTargetsPerRolloutGroup();
singleGroupsValidation(lastRow);
}

private void singleGroupsValidation(final GroupRow lastRow) {
final boolean hasRemainingTargetsError = validationStatus == ValidationStatus.INVALID;
final int maxTargets = quotaManagement.getMaxTargetsPerRolloutGroup();

for (int i = 0; i < groupRows.size(); ++i) {
final GroupRow row = groupRows.get(i);
// do not mask the 'remaining targets' error
if (hasRemainingTargetsError && row.equals(lastRow)) {
continue;
}
row.resetError();
final Long count = groupsValidation.getTargetsPerGroup().get(i);
if (count != null && count > maxTargets) {
row.setError(i18n.getMessage(MESSAGE_ROLLOUT_MAX_GROUP_SIZE_EXCEEDED, maxTargets));
setValidationStatus(ValidationStatus.INVALID);
if (groupsValidation != null) {
final Long count = groupsValidation.getTargetsPerGroup().get(i);
if (count != null && count > maxTargets) {
row.setError(i18n.getMessage(MESSAGE_ROLLOUT_MAX_GROUP_SIZE_EXCEEDED, maxTargets));
setValidationStatus(ValidationStatus.INVALID);
}
}
}

}

private List<RolloutGroupCreate> getGroupsFromRows() {
Expand Down Expand Up @@ -463,12 +472,16 @@ private void removeGroupRow(final GroupRow groupRow) {
private void validateMandatoryPercentage(final Object value) {
if (value != null) {
final String message = i18n.getMessage("message.rollout.field.value.range", 0, 100);
RangeValidator rangeValidator;
if (value instanceof Float) {
new FloatRangeValidator(message, 0F, 100F).validate(value);
}
if (value instanceof Integer) {
new IntegerRangeValidator(message, 0, 100).validate(value);
rangeValidator = new FloatRangeValidator(message, 0F, 100F);
} else if (value instanceof Integer) {
rangeValidator = new IntegerRangeValidator(message, 0, 100);
} else {
throw new Validator.InvalidValueException(i18n.getMessage("message.enter.number"));
}
rangeValidator.setMinValueIncluded(false);
rangeValidator.validate(value);
} else {
throw new Validator.EmptyValueException(i18n.getMessage("message.enter.number"));
}
Expand Down Expand Up @@ -615,7 +628,7 @@ public void populateByGroup(final RolloutGroup group) {
targetFilterQuery.setValue(group.getTargetFilterQuery());
populateTargetFilterQuery(group);

targetPercentage.setValue(String.format("%.2f", group.getTargetPercentage()));
targetPercentage.setValue(String.format(getCurrentLocale(), "%.2f", group.getTargetPercentage()));
triggerThreshold.setValue(group.getSuccessConditionExp());
errorThreshold.setValue(group.getErrorConditionExp());

Expand Down

0 comments on commit 3b15e80

Please sign in to comment.