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.

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

1 Comment

Same error when i disable all inspections except java

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.