Skip to content

Commit 1ea0696

Browse files
author
yevhenii-nadtochii
committed
Fix compilation of the old validation
1 parent e769ddc commit 1ea0696

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

java-runtime/src/main/java/io/spine/validate/MessageValidator.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ public void visitPattern(PatternConstraint constraint) {
132132
.filter(value -> partialMatch
133133
? noPartialMatch(compiledPattern, (String) value)
134134
: noCompleteMatch(compiledPattern, (String) value))
135-
.map(value -> violation(constraint, fieldValue, value)
136-
.toBuilder()
137-
.addParam(regex)
138-
.build())
135+
.map(value -> violation(constraint, fieldValue, value))
139136
.forEach(violations::add);
140137
}
141138

@@ -176,11 +173,7 @@ public void visitGoesWith(GoesConstraint constraint) {
176173
);
177174
var withField = declaration.get();
178175
if (!value.isDefault() && fieldValueNotSet(withField)) {
179-
var withFieldNotSet = violation(constraint, value).toBuilder()
180-
.addParam(field.name().value())
181-
.addParam(withFieldName)
182-
.build();
183-
violations.add(withFieldNotSet);
176+
violations.add(violation(constraint, value));
184177
}
185178
}
186179

@@ -226,7 +219,7 @@ public void visitRequiredOneof(IsRequiredConstraint constraint) {
226219
var oneofField = Field.named(oneofName.value());
227220
var targetType = constraint.targetType();
228221
var violation = ConstraintViolation.newBuilder()
229-
.setMsgFormat(constraint.errorMessage(message.context()))
222+
.setMessage(toTemplate(constraint.errorMessage(message.context())))
230223
.setFieldPath(oneofField.path())
231224
.setTypeName(targetType.name().value())
232225
.build();
@@ -347,7 +340,7 @@ private static ConstraintViolation violation(Constraint constraint,
347340
var fieldPath = context.fieldPath();
348341
var typeName = constraint.targetType().name();
349342
var violation = ConstraintViolation.newBuilder()
350-
.setMsgFormat(constraint.errorMessage(context))
343+
.setMessage(toTemplate(constraint.errorMessage(context)))
351344
.setFieldPath(fieldPath)
352345
.setTypeName(typeName.value());
353346
if (violatingValue != null) {
@@ -369,4 +362,12 @@ private static Any toFieldValue(Object violatingValue) {
369362
}
370363
return TypeConverter.toAny(violatingValue);
371364
}
365+
366+
// Old error messages are incompatible with new ones.
367+
// They will have not processed `%s` placeholders.
368+
private static TemplateString toTemplate(String printfString) {
369+
return TemplateString.newBuilder()
370+
.setWithPlaceholders(printfString)
371+
.build();
372+
}
372373
}

0 commit comments

Comments
 (0)