Rejected
Details
Assignee
UnassignedUnassignedReporter
selioteselioteBug Testcase Reminder (view)
Bug reports should generally be accompanied by a test case!
Bug Testcase Reminder (edit)
Bug reports should generally be accompanied by a test case!
Participants
Marko BekhtaselioteComponents
Affects versions
Priority
Critical
Details
Details
Assignee
Unassigned
UnassignedReporter
seliote
selioteBug Testcase Reminder (view)
Bug reports should generally be accompanied by a test case!
Bug Testcase Reminder (edit)
Bug reports should generally be accompanied by a test case!
Participants
Marko Bekhta
seliote
Components
Affects versions
Priority
Created September 12, 2021 at 5:13 AM
Updated December 12, 2024 at 11:38 AM
Resolved December 12, 2024 at 11:38 AM
Dear professor, thanks for read my confuse.
I had create a custom `ConstraintValidator`, code like those:
```
...
@Slf4j
public class PathValidator implements ConstraintValidator<Path, String> {
private final MlbService mlbService;
private final Set<String> catalogSet = new CopyOnWriteArraySet<>();
private final Set<String> extensionSet = new CopyOnWriteArraySet<>();
// path regex
private final Pattern pathPattern = Pattern.compile("^(\\w+)/(\\w)/(\\w)/([
w-]{36})\\.(
w+)$");
@Autowired
public PathValidator(MlbService mlbService) {
this.mlbService = mlbService;
}
@Override
public void initialize(Path constraintAnnotation) {
catalogSet.addAll(mlbService.minioSupportCatalog());
extensionSet.addAll(mlbService.minioSupportExtension());
}
@Override
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
var matcher = pathPattern.matcher(s);
if (!matcher.find()) {
log.warn("Minio path {} is illegal", s);
return false;
}
var catalog = matcher.group(1);
var extension = matcher.group(5);
if (catalogSet.contains(catalog) && extensionSet.contains(extension)) {
return true;
} else {
log.warn("Minio path {} is illegal, catalog or extension illegal", s);
return false;
}
}
}
```
`MlbService` is a Spring Service Bean, i need inject this bean at constructor because it had parse some config from yaml.
JSR 303 annotation is named `@Path`.
```
...
@Constraint(validatedBy = {PathValidator.class})
...
public @interface Path {
...
}
```
But i had some problem.
The @Path is normal when i annotated it at method parameters or return value, but when i use it at JPA entity and repository interface is annotated with `@Validated`, and call the save method or others, then , i will get `HV000064: Unable to instantiate ConstraintValidator` and `NoSuchMethodException: ...PathValidator.<init>()`
I am very very confuse about it.
and i try to debug the source code, i found in normal case the `ValidatorFactory` is `SpringConstraintValidatorFactory`, but at abnormal case is `ConstraintValidatorFactoryImpl`, `ConstraintValidatorFactoryImpl` find no args constructor at ConstraintValidator define, so that get an NoSuchMethodException.
I had search this issue at google, but no useful information found, i am very very confuse about this, that bothers me the most.
And the attachment is the full releate code.
Thank you for reading this, I look forward to receiving your reply.