title: Kryo Serializer IllegalAccessError at runtime
body: <p>We are trying to use Kryo Serializer to serialize our application object to push them in a kafka stream.</p>
  
  <p>The serialization code has</p>
  
  <pre><code>   private ThreadLocal&lt;Kryo&gt; kryos = new ThreadLocal&lt;Kryo&gt;() {
          protected Kryo initialValue() {
              Kryo kryo = new Kryo();
              kryo.addDefaultSerializer(MyApp.class, new MyAppKyroSerializer());
              return kryo;
          };
      };
  </code></pre>
  
  <p>The serialize method is:</p>
  
  <pre><code> @Override
      public byte[] serialize(String topic, MyApp data) {
  
          ByteBufferOutput output = new ByteBufferOutput(100);
  
          kryos.get().writeObject(output, data);
          return output.toBytes();
      }
  </code></pre>
  
  <p>While executing the Application we are getting the following IllegalAccessError:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalAccessError: tried to access field com.esotericsoftware.kryo.io.Output.capacity from class com.esotericsoftware.kryo.io.ByteBufferOutput
      at com.esotericsoftware.kryo.io.ByteBufferOutput.&lt;init&gt;(ByteBufferOutput.java:66)
      at com.esotericsoftware.kryo.io.ByteBufferOutput.&lt;init&gt;(ByteBufferOutput.java:58)
      at com.mycom.serializer.MyAppSerializer.serialize(MyAppSerializer.java:43)
  </code></pre>
  
  <p>This is strange because ByteBufferOutput extends Output and capacity is a protected field.</p>