question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IndexOutOfBoundsException (v3.0.4)

See original GitHub issue
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
	at java.util.ArrayList.rangeCheck(ArrayList.java:653)
	at java.util.ArrayList.get(ArrayList.java:429)
	at java.util.Collections$UnmodifiableList.get(Collections.java:1309)
	at org.javers.repository.sql.finders.CdoSnapshotFinder.lambda$getLatest$1(CdoSnapshotFinder.java:54)
	at org.javers.repository.sql.finders.CdoSnapshotFinder.getLatest(CdoSnapshotFinder.java:52)
	at org.javers.repository.sql.JaversSqlRepository.getLatest(JaversSqlRepository.java:46)
	at org.javers.repository.api.JaversExtendedRepository.getLatest(JaversExtendedRepository.java:81)
	at org.javers.core.snapshot.GraphShadowFactory.createLatestShadow(GraphShadowFactory.java:29)
	at org.javers.core.snapshot.GraphSnapshotFacade.createLatestShadow(GraphSnapshotFacade.java:22)
	at org.javers.core.commit.CommitFactory.create(CommitFactory.java:68)
	at org.javers.core.JaversCore.commit(JaversCore.java:80)
	at org.javers.spring.jpa.JaversTransactionalDecorator.commit(JaversTransactionalDecorator.java:63)
	at org.javers.spring.jpa.JaversTransactionalDecorator$$FastClassBySpringCGLIB$$acb40bd0.invoke(<generated>)
	at org.javers.spring.jpa.JaversTransactionalDecorator$$EnhancerBySpringCGLIB$$7578d67f.commit(<generated>)
	at org.javers.spring.auditable.aspect.springdata.OnSaveAuditChangeHandler.handle(OnSaveAuditChangeHandler.java:18)
	at org.javers.spring.auditable.aspect.springdata.JaversSpringDataAuditableRepositoryAspect.applyVersionChange(JaversSpringDataAuditableRepositoryAspect.java:80)
	at org.javers.spring.auditable.aspect.springdata.JaversSpringDataAuditableRepositoryAspect.applyVersionChanges(JaversSpringDataAuditableRepositoryAspect.java:75)
	at org.javers.spring.auditable.aspect.springdata.JaversSpringDataAuditableRepositoryAspect.lambda$onVersionEvent$0(JaversSpringDataAuditableRepositoryAspect.java:56)
	at org.javers.spring.auditable.aspect.springdata.JaversSpringDataAuditableRepositoryAspect.onVersionEvent(JaversSpringDataAuditableRepositoryAspect.java:53)
	at org.javers.spring.auditable.aspect.springdata.JaversSpringDataAuditableRepositoryAspect.onSaveExecuted(JaversSpringDataAuditableRepositoryAspect.java:47)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
igslznevcommented, Mar 24, 2017

Had same problem, after looking at source code can say, that IndexOutOfBoundsException happens when you try to rerun your application and first action (in my case) is trying to view audit change detail.

Want you to notice, that in this case in javers/javers-persistence-sql/src/main/java/org/javers/repository/sql/repositories/GlobalIdRepository.java in this method:

    public Optional<Long> findGlobalIdPk(GlobalId globalId) {
        if (disableCache){
            return findGlobalIdPkInDB(globalId);
        }

        Long foundPk = globalIdPkCache.getIfPresent(globalId);

        if (foundPk != null){
            return Optional.of(foundPk);
        }

        Optional<Long> fresh = findGlobalIdPkInDB(globalId);
        if (fresh.isPresent()){
            globalIdPkCache.put(globalId, fresh.get());
        }

        return fresh;
    }

Instead of taking value from cache it goes to findGlobalIdPkInDB(globalId) method as you can see. So, basically, to recreate this bug you must trigger this method.

So the problem is in jsonConverter.toJson(((InstanceId)globalId).getCdoId()) in this section of findGlobalIdPkInDB(globalId) method (don’t know about other cases).

//...
 else if (globalId instanceof InstanceId){
            query
                .where(GLOBAL_ID_LOCAL_ID + " = :localId ")
                .withArgument("localId", jsonConverter.toJson(((InstanceId)globalId).getCdoId()))
                .append("AND " + GLOBAL_ID_TYPE_NAME + " = :qualifiedName ")
                .withArgument("qualifiedName", globalId.getTypeName());
        }
//...

Argument localId is becomes like, for example, ""1111"" instead of "1111" so querying DB returns nothing. I think that jsonConverter.toJson(((InstanceId)globalId).getCdoId()) causes it and it must be replaced with just globalId.getCdoId() to prevent problem so it looks like this:

//...
query
    .where(GLOBAL_ID_LOCAL_ID + " = :localId ")
    .withArgument("localId", globalId.getCdoId())
    .append("AND " + GLOBAL_ID_TYPE_NAME + " = :qualifiedName ")
    .withArgument("qualifiedName", globalId.getTypeName());
//...

I am using PostgreSQL DB, if it might help to resolve this problem.

0reactions
minhchau110883commented, Jul 4, 2018

This issue is the same with issue I just report few minutes ago (https://github.com/javers/javers/issues/685) Your test case alway pass because before you already call javers.commit() before, and it stored in cache.

To reproduce this issue, you can try with some step as below

  1. Create new Springboot project and integrate it ith Javers
  2. Start project and insert/update some information
  3. Stop server and start again (The reason is I want to clean cache)
  4. Call finsSnapshot with InstanceId
Read more comments on GitHub >

github_iconTop Results From Across the Web

Exception in thread "main" java.lang ...
While executing below code I'm getting: (Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 3, Size: 3).
Read more >
java.lang.IndexOutOfBoundsException: Index: 46, Size: 46
Hey, I've recently opened a new 1.7.10 server with over 130 mods, numerous people have been having the same crash and I have...
Read more >
EWAHCompressedBitmap (JavaEWAH 0.6.0 API) - Javadoc.io
This implements the patent-free(1) EWAH scheme. Roughly speaking, it is a 64-bit variant of the BBC compression scheme used by Oracle for its...
Read more >
java.lang.IndexOutOfBoundsException: Index: 3999, Size: 4000 ...
And update forge while you're at it. EnderIO: No known problems detected. ... GL Caps: Using GL 1.3 multitexturing. Using framebuffer objects because...
Read more >
IndexOutOfBoundsException while reading large TIFF file
1 Standard GIF image reader · 2 Standard BMP Image Reader · 3 Standard WBMP Image Reader · 4 Standard PNG image reader...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found