java.lang.NullPointerException

Spring JIRA | Petar Tahchiev | 2 years ago
  1. 0

    Hello, I have this simple reader: {code} @StepScope @Bean(name = {"defaultAbstractEntityReader", "abstractEntityReader"}) public ItemReader<List<AbstractCatalogableEntityModel>> defaultAbstractEntityReader() { final java.util.Map<String, Object> properties = new HashMap<>(); properties.put("javax.persistence.jdbc.user", configurationService.getConfiguration().getString("db.username")); properties.put("javax.persistence.jdbc.password", configurationService.getConfiguration().getString("db.password")); properties.put("javax.persistence.jdbc.driver", configurationService.getConfiguration().getString("db.driver")); properties.put("javax.persistence.jdbc.url", configurationService.getConfiguration().getString("db.url")); final JpaPagingItemReader<List<AbstractCatalogableEntityModel>> entityReader = new JpaPagingItemReader<>(); entityReader.setEntityManagerFactory(entityManager.getEntityManagerFactory()); entityReader.setParameterValues(properties); entityReader.setQueryString("select p from product p"); entityReader.setPageSize(1000); return entityReader; } {code} and when I start the job I see this null pointer exception: {code} java.lang.NullPointerException at org.springframework.batch.item.database.JpaPagingItemReader.doReadPage(JpaPagingItemReader.java:196) at org.springframework.batch.item.database.AbstractPagingItemReader.doRead(AbstractPagingItemReader.java:108) at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:83) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) {code} which happens here on {{JpaPagingItemReader:196}} {code} if (transacted) { tx = entityManager.getTransaction(); {code} and, yes, the entityManager is {{null}}. I can see it being instantiated on line 177: {code} entityManager = entityManagerFactory.createEntityManager(jpaPropertyMap); {code} so I put a breakpoint there, but it never goes through that breakpoint so it always stays {{null}}.

    Spring JIRA | 2 years ago | Petar Tahchiev
    java.lang.NullPointerException
  2. 0

    Hello, I have this simple reader: {code} @StepScope @Bean(name = {"defaultAbstractEntityReader", "abstractEntityReader"}) public ItemReader<List<AbstractCatalogableEntityModel>> defaultAbstractEntityReader() { final java.util.Map<String, Object> properties = new HashMap<>(); properties.put("javax.persistence.jdbc.user", configurationService.getConfiguration().getString("db.username")); properties.put("javax.persistence.jdbc.password", configurationService.getConfiguration().getString("db.password")); properties.put("javax.persistence.jdbc.driver", configurationService.getConfiguration().getString("db.driver")); properties.put("javax.persistence.jdbc.url", configurationService.getConfiguration().getString("db.url")); final JpaPagingItemReader<List<AbstractCatalogableEntityModel>> entityReader = new JpaPagingItemReader<>(); entityReader.setEntityManagerFactory(entityManager.getEntityManagerFactory()); entityReader.setParameterValues(properties); entityReader.setQueryString("select p from product p"); entityReader.setPageSize(1000); return entityReader; } {code} and when I start the job I see this null pointer exception: {code} java.lang.NullPointerException at org.springframework.batch.item.database.JpaPagingItemReader.doReadPage(JpaPagingItemReader.java:196) at org.springframework.batch.item.database.AbstractPagingItemReader.doRead(AbstractPagingItemReader.java:108) at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:83) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) {code} which happens here on {{JpaPagingItemReader:196}} {code} if (transacted) { tx = entityManager.getTransaction(); {code} and, yes, the entityManager is {{null}}. I can see it being instantiated on line 177: {code} entityManager = entityManagerFactory.createEntityManager(jpaPropertyMap); {code} so I put a breakpoint there, but it never goes through that breakpoint so it always stays {{null}}.

    Spring JIRA | 2 years ago | Petar Tahchiev
    java.lang.NullPointerException
  3. 0

    Adding @JobScope on an ItemReader makes it fail

    Stack Overflow | 1 year ago | Matthieu Lebigre
    java.lang.NullPointerException: null
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  1. tvrmsmith 1 times, last 4 months ago
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.NullPointerException

    No message provided

    at org.springframework.batch.item.database.JpaPagingItemReader.doReadPage()
  2. Spring Batch Infrastructure
    AbstractItemCountingItemStreamItemReader.read
    1. org.springframework.batch.item.database.JpaPagingItemReader.doReadPage(JpaPagingItemReader.java:196)
    2. org.springframework.batch.item.database.AbstractPagingItemReader.doRead(AbstractPagingItemReader.java:108)
    3. org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:83)
    3 frames
  3. Java RT
    Method.invoke
    1. sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2. sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    3. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    4. java.lang.reflect.Method.invoke(Method.java:601)
    4 frames
  4. Spring AOP
    JdkDynamicAopProxy.invoke
    1. org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    2. org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    3. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    4. org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
    5. org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
    6. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    7. org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    7 frames