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

ArrayIndexOutOfBoundsException on different order of method calls to PatchMapper.builder() #17

Open
frankwis opened this issue Mar 3, 2017 · 1 comment
Labels

Comments

@frankwis
Copy link
Member

frankwis commented Mar 3, 2017

Order of method calls to PatchMapper.builder() impacts deserialization:

PatchMapper serializer = PatchMapper.builder()
                .withType(Bimmel.class)
                .with(PatchMapper.arrayBuilder()
                        .withAvroPrimitives()
                        .withCustomTypes()
                        .build())
                .nullable()
                .withAvroPrimitives()
                .build();

PatchMapper deserializer = PatchMapper.builder()
                .withType(Bimmel.class)
                .with(PatchMapper.arrayBuilder()
                        .withCustomTypes()
                        .withAvroPrimitives()
                        .build())
                .nullable()
                .withAvroPrimitives()
                .build();

byte[] bytes = serializer.toBytes(patch);
assertThat(patch, is(equalTo(deserializer.toPatch(bytes))));
java.lang.ArrayIndexOutOfBoundsException: -27

	at org.apache.avro.io.parsing.Symbol$Alternative.getSymbol(Symbol.java:416)
	at org.apache.avro.io.ResolvingDecoder.doAction(ResolvingDecoder.java:290)
	at org.apache.avro.io.parsing.Parser.advance(Parser.java:88)
	at org.apache.avro.io.ResolvingDecoder.readIndex(ResolvingDecoder.java:267)
	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:178)
	at org.apache.avro.reflect.ReflectDatumReader.readCollection(ReflectDatumReader.java:219)
	at org.apache.avro.reflect.ReflectDatumReader.readArray(ReflectDatumReader.java:137)
	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:176)
	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:152)
	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:178)
	at org.apache.avro.reflect.ReflectDatumReader.readField(ReflectDatumReader.java:302)
	at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:230)
	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:174)
	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:152)
	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:178)
	at org.apache.avro.reflect.ReflectDatumReader.readCollection(ReflectDatumReader.java:219)
	at org.apache.avro.reflect.ReflectDatumReader.readArray(ReflectDatumReader.java:137)
	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:176)
	at org.apache.avro.reflect.ReflectDatumReader.readField(ReflectDatumReader.java:302)
	at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:230)
	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:174)
	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:152)
	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:144)
	at io.datanerds.avropatch.serialization.PatchMapper.toPatch(PatchMapper.java:46)
	at io.datanerds.avropatch.serialization.PatchMapperTest.unionTest(PatchMapperTest.java:111)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

It looks like the order within Avro's schema union is crucial for resolving the types. Need to be deterministic on creation of the union list (e.g. alphabetical order).

@frankwis frankwis added the bug label Mar 3, 2017
@kirkvicent
Copy link

did you find out what's wrong and how to fix it ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants