Correctness33 - SpotBugsExtensionForSpringFrameWork/CS5098 GitHub Wiki

Correctness - Custom Exception in Bean Creation Process

Description

A bean that throws an exception during its creation process; a simplified sample to easily exemplify and understand the problem is throwing an exception in the constructor of the bean:

@Component
public class BeanA {

    public BeanA() {
        super();
        throw new NullPointerException();
    }
    ...
}

Theory

Solution

  1. Remove throw exception action
  2. Data error or logical error.

Link

https://stackoverflow.com/questions/12706857/spring-instanciate-a-bean-with-a-class-which-throws-an-exception

https://www.yawintutor.com/beaninstantiationexception-failed-to-instantiate-constructor-threw-exception/