Uploaded image for project: 'Apache Avro'
  1. Apache Avro
  2. AVRO-1635

C++ schema aware encoders throw tr1::bad_weak_ptr exception for recursive schema

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.7.7
    • Fix Version/s: 1.9.0
    • Component/s: c++
    • Environment:

      Ubuntu 12.04, gcc 4.6.4

    • Tags:
      c++ avro encoder

      Description

      Encoding an object with a recursive schema fails when using a jsonEncoder or a validatingEncoder. Here is an example:

      Output:

      terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_weak_ptr> >'
        what():  tr1::bad_weak_ptr
      
      container.json
      {
        "name": "Container",
        "doc": "Container to demonstrate the weak_ptr exception.",
        "type": "record",
        "fields": [{
          "name": "field",
          "type": {
            "name": "Object",
            "type": "record",
            "fields": [{
              "name": "value",
              "type": [
                "string",
                {"type": "map", "values": "Object"}
              ]
            }]
          }
        }]
      }
      
      example.cc
      #include <fstream>
      
      #include <avro/Compiler.hh>
      #include <avro/Encoder.hh>
      #include <avro/Stream.hh>
      #include <avro/ValidSchema.hh>
      
      #include "container.hh"
      
      int
      main()
      {
          std::ifstream ifs("container.json");
          avro::ValidSchema schema;
          avro::compileJsonSchema(ifs, schema);
      
          std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream();
      
          // Either one fails, here we use the jsonEncoder
          // avro::EncoderPtr encoder = avro::jsonEncoder(schema);
          avro::EncoderPtr encoder = avro::validatingEncoder(schema, avro::binaryEncoder());
          
          // An encoder that doesn't know the schema works fine
          // avro::EncoderPtr encoder = avro::binaryEncoder();
      
          encoder->init(*out);
      
          Container container;
          std::map<std::string, Object > object;
      
          // Note that it doesn't fail if we don't insert a value into the map
          object["a"].value.set_string("x");
      
          container.field.value.set_map(object);
          avro::encode(*encoder, container);
      
          return 0;
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                wmatthews William Matthews
                Reporter:
                Heye Heye Vöcking
              • Votes:
                3 Vote for this issue
                Watchers:
                12 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: