@@ -132,10 +132,7 @@ public void visitPattern(PatternConstraint constraint) {
132
132
.filter (value -> partialMatch
133
133
? noPartialMatch (compiledPattern , (String ) value )
134
134
: 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 ))
139
136
.forEach (violations ::add );
140
137
}
141
138
@@ -176,11 +173,7 @@ public void visitGoesWith(GoesConstraint constraint) {
176
173
);
177
174
var withField = declaration .get ();
178
175
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 ));
184
177
}
185
178
}
186
179
@@ -226,7 +219,7 @@ public void visitRequiredOneof(IsRequiredConstraint constraint) {
226
219
var oneofField = Field .named (oneofName .value ());
227
220
var targetType = constraint .targetType ();
228
221
var violation = ConstraintViolation .newBuilder ()
229
- .setMsgFormat ( constraint .errorMessage (message .context ()))
222
+ .setMessage ( toTemplate ( constraint .errorMessage (message .context () )))
230
223
.setFieldPath (oneofField .path ())
231
224
.setTypeName (targetType .name ().value ())
232
225
.build ();
@@ -347,7 +340,7 @@ private static ConstraintViolation violation(Constraint constraint,
347
340
var fieldPath = context .fieldPath ();
348
341
var typeName = constraint .targetType ().name ();
349
342
var violation = ConstraintViolation .newBuilder ()
350
- .setMsgFormat ( constraint .errorMessage (context ))
343
+ .setMessage ( toTemplate ( constraint .errorMessage (context ) ))
351
344
.setFieldPath (fieldPath )
352
345
.setTypeName (typeName .value ());
353
346
if (violatingValue != null ) {
@@ -369,4 +362,12 @@ private static Any toFieldValue(Object violatingValue) {
369
362
}
370
363
return TypeConverter .toAny (violatingValue );
371
364
}
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
+ }
372
373
}
0 commit comments