3

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?

zur
  • 1,121
  • 1
  • 11
  • 21
  • 2
    Configure FindBugs to not flag it? By far the fastest and easiest workaround, compared to any possible alternatives. – Kayaman Jan 20 '17 at 09:53
  • I was looking more towards how not to generate the extra IF in the first place – zur Jan 20 '17 at 10:01
  • 2
    I'm sure you were, but I provided the fastest method. You can of course find the code responsible for generating that bytecode, and fix it yourself. Don't forget to send the fix to the spring developers so they can incorporate it in a future release. – Kayaman Jan 20 '17 at 10:03
  • Letting FindBugs check generated code isn't very useful. – Jesper Jan 20 '17 at 10:29

0 Answers0