-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
Should _ensureRoom in ProtobufGenerator.writeString()? #94
Comments
Sounds and looks like a bug. Check for space should be done in Reproduction would be great although I understand it is not trivial to write. |
Can be reproduced by the following code: import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.protobuf.ProtobufMapper;
import com.fasterxml.jackson.dataformat.protobuf.schema.ProtobufSchema;
import com.fasterxml.jackson.dataformat.protobuf.schemagen.ProtobufSchemaGenerator;
import java.io.ByteArrayOutputStream;
import org.junit.Test;
/**
* Created by marsqing on 14/06/2017.
*/
public class StringTest {
@Test
public void stringTest() throws Exception {
Pojo13 p = new Pojo13();
// near 8000, so index out of bounds at 8000
p.setValue1(makeString(7995));
p.setValue2(makeString(7995));
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ProtobufMapper mapper = new ProtobufMapper();
mapper.writer(getSchema(mapper, p.getClass())).writeValue(bout, p);
}
private ProtobufSchema getSchema(ObjectMapper mapper, Class<?> clazz) throws Exception {
ProtobufSchemaGenerator gen = new ProtobufSchemaGenerator();
mapper.acceptJsonFormatVisitor(clazz, gen);
return gen.getGeneratedSchema();
}
private String makeString(int len) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++) {
sb.append("a");
}
return sb.toString();
}
public static class Pojo13 {
private String value1;
private String value2;
public Pojo13() {
}
public String getValue1() {
return value1;
}
public void setValue1(String value1) {
this.value1 = value1;
}
public String getValue2() {
return value2;
}
public void setValue2(String value2) {
this.value2 = value2;
}
}
}
|
so, I hope this problem could be fixed as soon as possible, thanks both of you : ) |
Yup, I'll try to get it fixed soon. Just need to re-familiarize with specific part -- unlike with many other jackson codecs, solution here is not to simplify flush contents (since due to nesting, not everything can actually be flushed) |
Ah. Actually, just like title said, just call It'd be good to have a test for nested case too, but since this method is used elsewhere I think it's ok to rely on its working. Unfortunately this went in 2.8 branch right after 2.8.9. On plus side it gets in 2.9.0.pr4 which I will release very soon. |
Great! Is it also necessary to call |
@marsqing which lines? I tried to have a quick look to see if there are obvious emission, but may have missed something. I'll check out |
Ok, no: |
With version 2.9.0.pr3, we encounter a ArrayIndexOutOfBoundsException
Occurs once every few hours, so not easily reproduced. Shall we call _ensureRoom when _encodeLongerString?
The text was updated successfully, but these errors were encountered: