- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Open
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)theme: aotAn issue related to Ahead-of-time processingAn issue related to Ahead-of-time processingtype: bugA general bugA general bug
Milestone
Description
demo project link: https://github.com/mingchiuli/demo
public class AnnoValidator implements ConstraintValidator<Anno, Pojo>  {
    @Resource
    private TestComponent testComponent;
    @Override
    public boolean isValid(Pojo value, ConstraintValidatorContext context) {
        testComponent.call();
        return true;
    }
}In Spring boot 3.3.6, I found if I injected a component in a implement Class of ConstraintValidator in JVM mode, it worked normal:
(console output:)
123
test
But It would generated a NullPointerExeception in GraalVM's native-image :
2024-12-12T12:46:54.279+08:00 ERROR 36733 --- [demo] [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: jakarta.validation.ValidationException: HV000028: Unexpected exception during isValid call.] with root cause
java.lang.NullPointerException: null
	at com.example.demo.pkg.AnnoValidator.isValid(AnnoValidator.java:14) ~[demo:na]
	at com.example.demo.pkg.AnnoValidator.isValid(AnnoValidator.java:7) ~[demo:na]
It seems the TestComponent can't be injected in native-image mode
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)theme: aotAn issue related to Ahead-of-time processingAn issue related to Ahead-of-time processingtype: bugA general bugA general bug