@PostConstructcallback may not define injection points. CDI only supports field, initializer and constructor injection. Also
@PostConstructcallbacks are called after the injection is performed. Weld is probably invoking this method twice - first as a regular initializer - injection is performed. And then a regular callback - idCache is null.
No. It's called only once.
But now I change it to @Inject for separate field and a post construct method.
When I use Weld 2.x, it told me PostConstruct should be with zero parameters or with parameters with @Inject annotated.
Maybe the warn comes because of the spec is not allowing parameters while weld, as a reference implementation, allows.
Maybe I should a constructor injection to be simpler.
Yes, separate the callback and injection (either use initializer or constructor injection). Just out of curiosity - what version of Weld 2 did you use? I've checked the source code of Weld 2.4 and should behave equally.
2.4. From 2.4.1 - 2.4.3 is the version I used before. Anyway, I use constructor injection now.
I did print a log, it's only called once in that case.