Skip to content

ClassCastException when transaction.watch(...) is used #2030

@medvedev

Description

@medvedev

Jedis code expects a String return value from transaction.watch(..) call, while redis server doesn't return one.
This leads to "shift" in Queuable.java's "pipelanedResponse", and then to ClassCastException (see stacktrace below), because Response (crated for "watch") is used to parse Long result of "incr" call.

By "expects" I mean MultiKeyCommandsPipeline.java and it's implementation MultiKeyPipelineBase.java

Code:

    public static void main(String[] args) {
        try (var cli = new Jedis("127.0.0.1");
            var transaction = cli.multi()) {
            transaction.watch("bar");
            transaction.incr("foo");
            transaction.exec();
        }
    }

Expected behavior

Executed successfully

Actual behavior

Exception in thread "main" java.lang.ClassCastException: class java.lang.Long cannot be cast to class [B (java.lang.Long and [B are in module java.base of loader 'bootstrap')
	at redis.clients.jedis.BuilderFactory$5.build(BuilderFactory.java:73)
	at redis.clients.jedis.BuilderFactory$5.build(BuilderFactory.java:70)
	at redis.clients.jedis.Response.build(Response.java:61)
	at redis.clients.jedis.Response.get(Response.java:37)
	at redis.clients.jedis.Transaction.exec(Transaction.java:53)
	at test.RedisCCE.main(RedisCCE.java:13)

Steps to reproduce:

  1. Start local redis instance
  2. Execute main code above

Redis / Jedis Configuration

Jedis version: 3.0.1

Redis version: 5.0.5

Java version: openjdk-12.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions