Jedis Scan throwing java.lang.IndexOutOfBoundsException

15 views
Skip to first unread message

Sylvester Musyoki

unread,
Jun 17, 2021, 7:40:39 AM6/17/21
to Jedis
Hi,
I have a Spring Boot Project running on Java 16 and using Jedis 2.8.0 (redis.clients:jedis:2.8.0).
Jedis scan method throws java.lang.IndexOutOfBoundsException when I scan using a pattern.
Below is the code snippet:

Jedis jedis = new Jedis();
String key ="My Search String"
String cursor = "0"; 
ScanParams sp = new ScanParams(); 
sp.match("*" + key + "*"); 
sp.count(1000); 
do { 
        ScanResult<String> ret = jedis.scan(cursor, sp); 
        .............More Logic .......................................
} while (!cursor.equals("0"));

Below is the error stack:
java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 1
        at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64) ~[na:na]
        at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70) ~[na:na]
        at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266) ~[na:na]
        at java.base/java.util.Objects.checkIndex(Objects.java:359) ~[na:na]
        at java.base/java.util.ArrayList.get(ArrayList.java:427) ~[na:na]
        at redis.clients.jedis.Jedis.scan(Jedis.java:3137) ~[jedis-2.8.0.jar:na]

The solution was working fine.
I hope someone can help me .
Thank you.

Sazzadul Hoque

unread,
Jun 17, 2021, 9:49:56 AM6/17/21
to jedis...@googlegroups.com
Hi Sylvester Musyoki,

First of all, may I know your inspiration behind using Jedis 2.8.0 (from 2015) with Java 16 (from 2020)?

About your query,

1.
The solution was working fine.
Did you change anything or is there anything changed after working fine?

2. Can the "jedis" object be used by multiple threads?

--
You received this message because you are subscribed to the Google Groups "Jedis" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jedis_redis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jedis_redis/1b7b84a2-496b-448b-b112-9beffdfe9539n%40googlegroups.com.

Sylvester Musyoki

unread,
Jun 17, 2021, 10:39:25 AM6/17/21
to Jedis
Hi Sazzadul Hoque,
Thanks for taking some time to look at my issue.

Actually, there is no inspiration behind using Jedis 2.8.0 and Java 16. The solution was originally running on Java 13 (non‑LTS) and after its Premier Support ended, I decided to update to Java 16 and I did not update any dependencies which seemed "okay" (still supported).

1. Did you change anything or is there anything changed after working fine?
     The only recent "change" was updating the Java and Gradle versions used, which was done early this year and the solution was working okay until the intermitted issues started coming up.

2. Can the "jedis" object be used by multiple threads?
     Yes, since the "jedis" object is declared as a global variable, although I have not implemented multithreading in my project.

Kind Regards,
Sylvester M.

Sazzadul Hoque

unread,
Jun 17, 2021, 10:54:45 AM6/17/21
to jedis...@googlegroups.com
I'm putting two suggestions for you.

1. Use JedisPool as the global variable. In methods, use Jedis from that pool. Try to avoid sharing same Jedis object among multiple methods.

2. I know, this will be a lot of work but try to upgrade your dependencies. At least update Jedis to 2.10.2.

Sylvester Musyoki

unread,
Jun 17, 2021, 11:03:24 AM6/17/21
to Jedis
Thanks for the suggestions.
I will share feedback ASAP
Reply all
Reply to author
Forward
0 new messages