avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karthik (JIRA)" <j...@apache.org>
Subject [jira] [Created] (AVRO-2095) Avro 1.8.2 encode in c++ - java.lang.ArrayIndexOutOfBoundsException
Date Mon, 09 Oct 2017 21:34:00 GMT
Karthik created AVRO-2095:
-----------------------------

             Summary: Avro 1.8.2 encode in c++ -  java.lang.ArrayIndexOutOfBoundsException
                 Key: AVRO-2095
                 URL: https://issues.apache.org/jira/browse/AVRO-2095
             Project: Avro
          Issue Type: New Feature
          Components: c++, java
    Affects Versions: 1.8.2
         Environment: C++, Java
            Reporter: Karthik


I have the following schema

{code:json}
[
    {
        "namespace": "com.test",
        "name": "MyDevice",
        "type": "record",
        "doc": "client device",
        "fields": [
            {
                "name": "deviceId",
                "type": [
                    "null",
                    "string"
                ],
                "default": null,
                "doc": "Usually unique MAC address"
            }
        ]
    },
    {
        "namespace": "com.test",
        "name": "Event",
        "type": "record",
        "doc": "event",
        "fields": [
            {
                "name": "myDevice",
                "type": [
                    "null",
                    "com.test.MyDevice"
                ],
                "default": null,
                "doc": "Device information"
            }
        ]
    }
]
{code}

I installed avro 1.8.2 on my ubuntu build machine and generated test.h using avrogencpp tool.

Then, I created binary encoded avro data as follows:


{code:c++}
    MyDevice device;
    device.deviceId.set_string("device1");
    Event event;
    event.myDevice.set_MyDevice(device);

    std::vector<char> bytes;
    std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream(1);
    avro::EncoderPtr e = avro::binaryEncoder();

    e->init(*out);
    avro::encode(*e, event);
    out->flush();
{code}

I deserialize my data in Java application as follows:

{code:java}

Schema schema = SchemaUtils.getSchemaFromFile("src/main/resources/schemas/test.avsc");

DatumReader<GenericRecord> genericDatumReader = new GenericDatumReader<>(schema);
        Decoder decoder = DecoderFactory.get().binaryDecoder(data, null);
        try {
            GenericRecord userData = genericDatumReader.read(null, decoder);
            System.out.println(userData);
        } catch (IOException e) {
            e.printStackTrace();
        }
{code}

And the result is 

{noformat}
java.lang.ArrayIndexOutOfBoundsException: 7
	at org.apache.avro.io.parsing.Symbol$Alternative.getSymbol(Symbol.java:424)
	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:179)
	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
	at org.apache.avro.generic.GenericDatumReader.readField(GenericDatumReader.java:232)
	at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:222)
	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:175)
	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:179)
	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
	at org.apache.avro.generic.GenericDatumReader.readField(GenericDatumReader.java:232)
	at org.apache.avro.generic.GenericDatumReader.readRecord(GenericDatumReader.java:222)
	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:175)
	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
	at org.apache.avro.generic.GenericDatumReader.readWithoutConversion(GenericDatumReader.java:179)
	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:153)
	at org.apache.avro.generic.GenericDatumReader.read(GenericDatumReader.java:145)
{noformat}

But if I do the same using a simple schema (without union), it works perfectly

{code:json}
{
        "namespace": "com.test",
        "name": "MyDevice",
        "type": "record",
        "doc": "client device",
        "fields": [
            {
                "name": "deviceId",
                "type": [
                    "null",
                    "string"
                ],
                "default": null,
                "doc": "Usually unique MAC address"
            }
        ]
    }
{code}

Any help appreciated ! Thanks ! 



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message