Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default text encoding assumes the ByteBuf is large enough for encoding the value #62

Closed
Ryan-ZA opened this issue Mar 4, 2018 · 2 comments
Milestone

Comments

@Ryan-ZA
Copy link

Ryan-ZA commented Mar 4, 2018

The following code gives an error:

        List<Tuple> batch = new ArrayList<>();
        batch.add(Tuple.of(79991, "batch one"));
        batch.add(Tuple.of(79992, "batch two"));
        batch.add(Tuple.of(79993, "batch three"));
        batch.add(Tuple.of(79994, "batch four"));

        conn.preparedBatch("SELECT $1::integer, $2::varchar(2048)", batch, event -> {
            if (event.succeeded()) {
                logger.info("Stored new batch of commands");
            } else {
                logger.info("Error storing batch of commands", event.cause());
            }
            async.complete();
        });

But with the following change (note added spaces in sql) the error disappears

        List<Tuple> batch = new ArrayList<>();
        batch.add(Tuple.of(79991, "batch one"));
        batch.add(Tuple.of(79992, "batch two"));
        batch.add(Tuple.of(79993, "batch three"));
        batch.add(Tuple.of(79994, "batch four"));

        conn.preparedBatch("SELECT $1::integer, $2::varchar(2048)                                                  ", batch, event -> {
            if (event.succeeded()) {
                logger.info("Stored new batch of commands");
            } else {
                logger.info("Error storing batch of commands", event.cause());
            }
            async.complete();
        });

The error that happens is

SEVERE: Unhandled exception
java.lang.IndexOutOfBoundsException: index: 253, length: 30 (expected: range(0, 256))
	at io.netty.buffer.AbstractByteBuf.checkIndex0(AbstractByteBuf.java:1360)
	at io.netty.buffer.AbstractByteBuf.checkIndex(AbstractByteBuf.java:1355)
	at io.netty.buffer.AbstractByteBuf.setCharSequence0(AbstractByteBuf.java:682)
	at io.netty.buffer.AbstractByteBuf.setCharSequence(AbstractByteBuf.java:672)
	at com.julienviet.pgclient.impl.codec.DataType.encodeText(DataType.java:655)
	at com.julienviet.pgclient.impl.codec.DataType$9.encodeBinary(DataType.java:244)
	at com.julienviet.pgclient.impl.codec.DataType$9.encodeBinary(DataType.java:234)
	at com.julienviet.pgclient.impl.codec.encoder.message.Bind.encode(Bind.java:154)
	at com.julienviet.pgclient.impl.codec.encoder.message.Bind.encode(Bind.java:167)
	at com.julienviet.pgclient.impl.SocketConnection.checkPending(SocketConnection.java:210)
	at com.julienviet.pgclient.impl.SocketConnection.bilto(SocketConnection.java:191)
	at com.julienviet.pgclient.impl.CommandBase.foo(CommandBase.java:54)
	at com.julienviet.pgclient.impl.SocketConnection.schedule(SocketConnection.java:181)
	at com.julienviet.pgclient.impl.ConnectionPool$PooledConnection.schedule(ConnectionPool.java:77)
	at com.julienviet.pgclient.impl.PgPoolImpl$1.lambda$onSuccess$0(PgPoolImpl.java:73)
	at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:339)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:748)
@vietj
Copy link
Member

vietj commented Mar 4, 2018

thanks will have a look soon

@vietj vietj added this to the 0.6.0 milestone Mar 4, 2018
@vietj
Copy link
Member

vietj commented Mar 4, 2018

it's not clear what you mean by space, your second example that works is not valid java code, so it's hard to spot the difference

@vietj vietj changed the title Error with batches depending on SQL string length Default text encoding assumes the ByteBuf is large enough for encoding the value Mar 4, 2018
@vietj vietj closed this as completed in eebbf98 Mar 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants