I needed to autowire a class member and I followed : http://stackoverflow.com/questions/19896870/why-is-my-spring-autowired-field-null
@Configurable was the thing that I needed and that worked fine...
Following is the snippet of constructor from the *.class which was generated after I compiled:
public HelloWorldClient() {
JoinPoint localJoinPoint2 = Factory.makeJP(ajc$tjp_1, this, this);
JoinPoint localJoinPoint1 = Factory.makeJP(ajc$tjp_0, this, this);
if ((this != null) && (getClass().isAnnotationPresent(Configurable.class))
&& (AnnotationBeanConfigurerAspect.ajc$if$bb0((Configurable) getClass().getAnnotation(Configurable.class))))
AnnotationBeanConfigurerAspect
.aspectOf()
.ajc$before$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$1$e854fa65(this);
if ((this != null)
&& (getClass().isAnnotationPresent(Configurable.class))
&& ((this == null) || (!getClass().isAnnotationPresent(Configurable.class)) || (!AnnotationBeanConfigurerAspect
.ajc$if$bb0((Configurable) getClass().getAnnotation(Configurable.class))))
&& (AbstractDependencyInjectionAspect.ajc$if$6f1(localJoinPoint1)))
AnnotationBeanConfigurerAspect
.aspectOf()
.ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(
this);
if ((!AnnotationBeanConfigurerAspect.ajc$if$bb0((Configurable) getClass().getAnnotation(Configurable.class)))
&& (AbstractDependencyInjectionAspect.ajc$if$6f1(localJoinPoint2)))
AnnotationBeanConfigurerAspect
.aspectOf()
.ajc$afterReturning$org_springframework_beans_factory_aspectj_AbstractDependencyInjectionAspect$2$1ea6722c(
this);
}
I also have findBugs plugin in the project, which says
Redundant nullcheck of this, which is known to be non-null in new packageName.ClassName
This error points to my constructor which does not have any line of code. I hope findBug is pointing to the generated byte code's line if ((this != null)
. Is there any workaround for this?