java.lang.NullPointerException

Spring JIRA | Chris Beams | 8 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  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 | 3 years ago | Petar Tahchiev
    java.lang.NullPointerException
  2. Speed up your debug routine!

    Automated exception search integrated into your IDE

  3. 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 | 3 years ago | Petar Tahchiev
    java.lang.NullPointerException
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.file.mapping.DefaultLineMapper.mapLine()
  2. Spring Batch Infrastructure
    AbstractItemCountingItemStreamItemReader.read
    1. org.springframework.batch.item.file.mapping.DefaultLineMapper.mapLine(DefaultLineMapper.java:21)
    2. org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFileItemReader.java:151)
    3. org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:61)
    3 frames
  3. Spring Batch Core
    SimpleChunkProvider.read
    1. org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:67)
    2. org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:111)
    2 frames