Spring Data Neo4j
  1. Spring Data Neo4j
  2. DATAGRAPH-206

Potential NullPointerException in Neo4jTemplate

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: 2.0.1
    • Fix Version/s: 2.1.RC2
    • Component/s: CORE
    • Labels:
      None

      Description

      When instantiating Neo4jTemplate with it's default constructor it does not automatically call the postConstruct(...) method of the MappingInfrastructure instance it creates. Thus the defaults do not apply and using the template results in NullPointerExceptions

        Activity

        Hide
        Mark Spritzler added a comment -

        Looking at the Neo4jTemplate class, its @PostConstruct method is the one that calls mappingInfrastructure.postConstruct, so in theory all constructors would react the same way. If your Neo4jTemplate is defined as a Spring Bean or spring-configured, then the BeanPostProcessor for @PostConstruct would call that Neo4jTemplate's @PostConstruct method (as long as the CommonAnnotationBeanPostProcessor is configured <context:annotation-config/>, which in turn calls the mappingInfrastructure's postConstruct method. If you are creating the template in code with new, then none of the constructors call the templates @PostConstruct method, and therefore none would call the MappingInfrastructure's postConstruct method.

        So this might mean the issue is really with all the constructors. Even though something else is masking the other constructor's problem with this.

        Show
        Mark Spritzler added a comment - Looking at the Neo4jTemplate class, its @PostConstruct method is the one that calls mappingInfrastructure.postConstruct, so in theory all constructors would react the same way. If your Neo4jTemplate is defined as a Spring Bean or spring-configured, then the BeanPostProcessor for @PostConstruct would call that Neo4jTemplate's @PostConstruct method (as long as the CommonAnnotationBeanPostProcessor is configured <context:annotation-config/>, which in turn calls the mappingInfrastructure's postConstruct method. If you are creating the template in code with new, then none of the constructors call the templates @PostConstruct method, and therefore none would call the MappingInfrastructure's postConstruct method. So this might mean the issue is really with all the constructors. Even though something else is masking the other constructor's problem with this.
        Hide
        Michael Hunger added a comment -

        It is now possible to construct a Neo4j-Template just with a GraphDatabase there is a MappingInfrastructureFactoryBean which takes care of creating the fully prepopulated Infrastructure instance which contains all the dependencies needed by Neo4j-Template.

        Show
        Michael Hunger added a comment - It is now possible to construct a Neo4j-Template just with a GraphDatabase there is a MappingInfrastructureFactoryBean which takes care of creating the fully prepopulated Infrastructure instance which contains all the dependencies needed by Neo4j-Template.

          People

          • Assignee:
            Michael Hunger
            Reporter:
            Oliver Gierke
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: