最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

IntelliJ - ignore "Not-null fields must be initialized" for injected fields - Stack Overflow

programmeradmin6浏览0评论

IntelliJ keeps telling me i have to initialize my injected fields. I know a workaround would be to create a ctor and annotate it with @Inject but i dont want to change all of my classes. So is there a way to tell IntelliJ to ignore this error in @Inject fields?

import jakarta.inject.Inject;
import org.eclipse.jdt.annotation.NonNull;

public class Foo {
    @NonNull
    @Inject
    private Bar bar;
}

Under Settings -> Inscpections -> Probable bugs -> Nullability problems -> "@NotNull field is not initialized" there is a checkbox that is called "Ignore fields which could be initialized implicitly" that is checked. But it doesn't work.

IntelliJ keeps telling me i have to initialize my injected fields. I know a workaround would be to create a ctor and annotate it with @Inject but i dont want to change all of my classes. So is there a way to tell IntelliJ to ignore this error in @Inject fields?

import jakarta.inject.Inject;
import org.eclipse.jdt.annotation.NonNull;

public class Foo {
    @NonNull
    @Inject
    private Bar bar;
}

Under Settings -> Inscpections -> Probable bugs -> Nullability problems -> "@NotNull field is not initialized" there is a checkbox that is called "Ignore fields which could be initialized implicitly" that is checked. But it doesn't work.

Share Improve this question edited Feb 5 at 9:51 unrated asked Feb 5 at 9:36 unratedunrated 2821 gold badge5 silver badges24 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I have one idea: The default inspection profile does inspections for all languages, irrespective if you use it in your project or not. Did you try with a new custom inspection profile, disable all non-java inspections there (or keep only the languages your project uses) and check again?

I had "Field injection is not recommended" many times popping up until I noticed those are wrt Spring Framework - and our project does not use Spring!

发布评论

评论列表(0)

  1. 暂无评论