java.lang.NullPointerException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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}}.
    via by Petar Tahchiev,
  • 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}}.
    via by Petar Tahchiev,
    • java.lang.NullPointerException at org.springframework.batch.item.file.mapping.DefaultLineMapper.mapLine(DefaultLineMapper.java:21) at org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFileItemReader.java:151) at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:61) at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:67) at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:111)

    Users with the same issue

    tvrmsmith
    5 times, last one,