java.lang.IllegalArgumentException: Total must not be less than the number of elements given!

Spring JIRA | Etki | 1 year ago
  1. 0

    Hi. I've been testing my spring-based software under load, during which something like 50 entities were created and inserted into empty database. At the same time, my background repository walker, which uses `findAll(Pageable pageable)` to infinitely walk through all entities, was searching for stale records to mark them as expired. In the middle of that process, i think, Spring component made two queries to database: count all records and then fetch necessary ones, and the first query counted lesser amount of records than second one returned. All of that resulted in an exception, since PageImpl expects content to be lesser than or equal to total records count: {code:java} Exception in thread "Maintenance // Stale redirect resolver" java.lang.IllegalArgumentException: Total must not be less than the number of elements given! at org.springframework.util.Assert.isTrue(Assert.java:68) at org.springframework.data.domain.PageImpl.<init>(PageImpl.java:47) at org.springframework.data.jpa.repository.support.SimpleJpaRepository.readPage(SimpleJpaRepository.java:498) at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:394) at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:363) at sun.reflect.GeneratedMethodAccessor256.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:414) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:399) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:371) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy73.findAll(Unknown Source) {code} I've been using that setup for three months, but that's the first time i ever meet that exception.

    Spring JIRA | 1 year ago | Etki
    java.lang.IllegalArgumentException: Total must not be less than the number of elements given!
  2. 0

    Hi. I've been testing my spring-based software under load, during which something like 50 entities were created and inserted into empty database. At the same time, my background repository walker, which uses `findAll(Pageable pageable)` to infinitely walk through all entities, was searching for stale records to mark them as expired. In the middle of that process, i think, Spring component made two queries to database: count all records and then fetch necessary ones, and the first query counted lesser amount of records than second one returned. All of that resulted in an exception, since PageImpl expects content to be lesser than or equal to total records count: {code:java} Exception in thread "Maintenance // Stale redirect resolver" java.lang.IllegalArgumentException: Total must not be less than the number of elements given! at org.springframework.util.Assert.isTrue(Assert.java:68) at org.springframework.data.domain.PageImpl.<init>(PageImpl.java:47) at org.springframework.data.jpa.repository.support.SimpleJpaRepository.readPage(SimpleJpaRepository.java:498) at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:394) at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:363) at sun.reflect.GeneratedMethodAccessor256.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:414) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:399) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:371) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) at com.sun.proxy.$Proxy73.findAll(Unknown Source) {code} I've been using that setup for three months, but that's the first time i ever meet that exception.

    Spring JIRA | 1 year ago | Etki
    java.lang.IllegalArgumentException: Total must not be less than the number of elements given!
  3. 0

    Spring Boot - Windows - Default Job 307: Job result summary - Spring CI

    spring.io | 1 year ago
    java.lang.IllegalArgumentException: Only the target location may be specified
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    How to return JSON data from spring Controller using @ResponseBody

    Stack Overflow | 1 year ago | Zahid Khan
    java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList
  6. 0

    CLI causes error with description option having white spaces

    GitHub | 1 year ago | nobeans
    java.lang.IllegalArgumentException: Only the target location may be specified

  1. batwalrus76 1 times, last 1 week ago
  2. kjhdofjosvs 1 times, last 3 weeks ago
  3. j.kienzle 1 times, last 1 month ago
  4. Luka 2 times, last 2 months ago
  5. andyglick 1 times, last 3 months ago
4 more registered users
29 unregistered visitors
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.IllegalArgumentException

    Total must not be less than the number of elements given!

    at org.springframework.util.Assert.isTrue()
  2. Spring Core
    Assert.isTrue
    1. org.springframework.util.Assert.isTrue(Assert.java:68)
    1 frame
  3. Spring Data Core
    PageImpl.<init>
    1. org.springframework.data.domain.PageImpl.<init>(PageImpl.java:47)
    1 frame
  4. Spring Data JPA
    SimpleJpaRepository.findAll
    1. org.springframework.data.jpa.repository.support.SimpleJpaRepository.readPage(SimpleJpaRepository.java:498)
    2. org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:394)
    3. org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:363)
    3 frames
  5. Java RT
    Method.invoke
    1. sun.reflect.GeneratedMethodAccessor256.invoke(Unknown Source)
    2. sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    3. java.lang.reflect.Method.invoke(Method.java:497)
    3 frames
  6. Spring Data Core
    RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke
    1. org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:414)
    2. org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:399)
    3. org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:371)
    3 frames
  7. Spring AOP
    ReflectiveMethodInvocation.proceed
    1. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    1 frame
  8. org.springframework.data
    DefaultMethodInvokingMethodInterceptor.invoke
    1. org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
    1 frame
  9. Spring AOP
    ReflectiveMethodInvocation.proceed
    1. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    1 frame
  10. Spring Data JPA
    CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke
    1. org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122)
    1 frame
  11. Spring AOP
    JdkDynamicAopProxy.invoke
    1. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    2. org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    3. org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    4. org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    4 frames
  12. com.sun.proxy
    $Proxy73.findAll
    1. com.sun.proxy.$Proxy73.findAll(Unknown Source)
    1 frame