PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, April 28, 2022

[FIXED] How to hide NullPointer Warnings (due to NoArgsConstructor with force=true) in IntelliJ?

 April 28, 2022     dropwizard, intellij-idea, lombok, warnings, weld     No comments   

Issue

I have created a Java application using Dropwizard and Weld. I have also included Lombok and I have currently annotated my service classes like:

@Slf4j
@ApplicationScoped
@NoArgsConstructor(force = true)
@RequiredArgsConstructor(onConstructor = @__({@Inject}))
public class MovieRequestService {

    private final MovieService movieService;
    private final ActorService actorService;

It works fine and I am happy with it. The RequiredArgsConstructor is useful for my Unit tests. The NoArgsConstructor is necessary for Weld. force = true has to be set because of the final keywords... But this also leads to the fact that IntelliJ warns me on every single place where I use the movieService or actorService....

What should I do? Can I get rid of the warnings?


Solution

"Force=true" parameter of @NoArgsConstructor annotation means that fields are initialized to @Nullable value, so the warnings of "Constant conditions & exceptions" inspection (Java | Probable bugs | Constant conditions & exceptions) about possible NullPointerException are correct. You may disable the inspection's option "Report problems that happen only on some code paths" to get rid of the warning.



Answered By - Olga Klisho
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing