{"action":"created","issue":{"url":"https://api.github.com/repos/EsotericSoftware/kryo/issues/373","repository_url":"https://api.github.com/repos/EsotericSoftware/kryo","labels_url":"https://api.github.com/repos/EsotericSoftware/kryo/issues/373/labels{/name}","comments_url":"https://api.github.com/repos/EsotericSoftware/kryo/issues/373/comments","events_url":"https://api.github.com/repos/EsotericSoftware/kryo/issues/373/events","html_url":"https://github.com/EsotericSoftware/kryo/issues/373","id":118332940,"number":373,"title":"kyro throw buffer underFlow  without input/output NOT closing, without multi-thread ","user":{"login":"wyzssw","id":4242774,"avatar_url":"https://avatars.githubusercontent.com/u/4242774?v=3","gravatar_id":"","url":"https://api.github.com/users/wyzssw","html_url":"https://github.com/wyzssw","followers_url":"https://api.github.com/users/wyzssw/followers","following_url":"https://api.github.com/users/wyzssw/following{/other_user}","gists_url":"https://api.github.com/users/wyzssw/gists{/gist_id}","starred_url":"https://api.github.com/users/wyzssw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wyzssw/subscriptions","organizations_url":"https://api.github.com/users/wyzssw/orgs","repos_url":"https://api.github.com/users/wyzssw/repos","events_url":"https://api.github.com/users/wyzssw/events{/privacy}","received_events_url":"https://api.github.com/users/wyzssw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-23T07:38:54Z","updated_at":"2016-04-08T23:08:28Z","closed_at":null,"body":"this is my exception stack \r\n```\r\nException in thread \"main\" com.esotericsoftware.kryo.KryoException: Buffer underflow.\r\nSerialization trace:\r\nright (org.apache.commons.lang3.tuple.ImmutablePair)\r\nbackingMap (com.google.common.collect.HashBasedTable)\r\nuserTable (com.xxxx.ecar.item.model.ItemStates)\r\n\tat com.esotericsoftware.kryo.io.Input.require(Input.java:199)\r\n\tat com.esotericsoftware.kryo.io.Input.readAscii_slow(Input.java:616)\r\n\tat com.esotericsoftware.kryo.io.Input.readAscii(Input.java:594)\r\n\tat com.esotericsoftware.kryo.io.Input.readString(Input.java:472)\r\n\tat com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:150)\r\n\tat com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:133)\r\n\tat com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:670)\r\n\tat com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:118)\r\n\tat com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:551)\r\n\tat com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:790)\r\n\tat com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:153)\r\n\tat com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:39)\r\n\tat com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:708)\r\n\tat com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)\r\n\tat com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:551)\r\n\tat com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:708)\r\n\tat com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)\r\n\tat com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:551)\r\n\tat com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:686)\r\n\tat com.xxxxx.ecar.item.rpc.serialize.KryoSerializers.readObject(KryoSerializers.java:61)\r\n\tat com.xxxxx.ecar.item.rpc.serialize.KryoSerializers.main(KryoSerializers.java:97)\r\n\r\n```\r\n\r\nthis is my whole code\r\n\r\n```\r\npackage com.xxxxx.serialize;\r\n\r\nimport java.io.ByteArrayInputStream;\r\nimport java.io.ByteArrayOutputStream;\r\nimport java.io.InputStream;\r\nimport java.io.OutputStream;\r\n\r\nimport org.apache.commons.lang3.tuple.ImmutablePair;\r\nimport org.objenesis.strategy.StdInstantiatorStrategy;\r\n\r\nimport com.esotericsoftware.kryo.Kryo;\r\nimport com.esotericsoftware.kryo.io.Input;\r\nimport com.esotericsoftware.kryo.io.Output;\r\nimport com.xxxx.ecar.item.model.ItemStates;\r\n\r\n/**\r\n * \r\n * @author \r\n *\r\n */\r\npublic final class KryoSerializers {\r\n  \r\n  private KryoSerializers(){}\r\n  \r\n  private static ThreadLocal<Kryo> kryos = new ThreadLocal<Kryo>() {\r\n    protected Kryo initialValue() {\r\n        Kryo kryo = new Kryo();\r\n        ((Kryo.DefaultInstantiatorStrategy) kryo.getInstantiatorStrategy()).setFallbackInstantiatorStrategy(new StdInstantiatorStrategy());\r\n        return kryo;\r\n    };\r\n  };\r\n  \r\n  public static void register(Class<?> type){\r\n    kryos.get().register(type);\r\n  }\r\n  \r\n  /**\r\n   * \r\n   * @param source\r\n   * @param type\r\n   * @return\r\n   */\r\n  public static <T> T readObject (InputStream source, Class<T> type) {\r\n    register(type);\r\n    Input input = new Input(source);\r\n    T result =   kryos.get().readObject(input, type);\r\n    return result;\r\n  }\r\n  \r\n  /**\r\n   * \r\n   * @param source\r\n   * @param type\r\n   * @return\r\n   */\r\n  public static <T> T readObject (byte[] source, Class<T> type) {\r\n    ByteArrayInputStream is = new ByteArrayInputStream(source);\r\n    Input input = new Input(is);\r\n    T result =   kryos.get().readObject(input, type);\r\n    input.close();\r\n    return result;\r\n  }\r\n  \r\n  /***\r\n   * \r\n   * @param sink \r\n   * @param object\r\n   */\r\n  public static void writeObject (OutputStream sink, Object object) {\r\n    Output output = new Output(sink);\r\n    kryos.get().writeObject(output, object);\r\n    output.flush();\r\n  }\r\n  \r\n  /**\r\n   * \r\n   * @param object\r\n   * @return\r\n   */\r\n  public static byte[] getBytes(Object object){\r\n    ByteArrayOutputStream os = new ByteArrayOutputStream();\r\n    Output output = new Output(os);\r\n    kryos.get().writeObject(output, object);\r\n    output.close();\r\n    return os.toByteArray();\r\n  }\r\n  \r\n  \r\n  public static void main(String[] args) {\r\n    ItemStates states = ItemStates.create();\r\n    states.getOrderTable().put(1L, 2, \"coupon\");\r\n    states.getStockTable().put(1, ImmutablePair.of(1, 2), ImmutablePair.of(3, 4));\r\n    states.getUserTable().put(ImmutablePair.of(1L, 2), 3L, 5);\r\n    byte[] data  =  KryoSerializers.getBytes(states);\r\n    System.out.println(KryoSerializers.readObject(data,ItemStates.class));\r\n  }\r\n\r\n}\r\n\r\n```\r\nand Itemstats.java\r\n\r\n```\r\npackage com.xxxx.model;\r\n\r\n\r\nimport java.io.Serializable;\r\n\r\nimport org.apache.commons.lang3.tuple.Pair;\r\n\r\nimport com.google.common.collect.HashBasedTable;\r\nimport com.google.common.collect.Table;\r\n\r\n/**\r\n *\r\n *\r\n * @author \r\n */\r\npublic class ItemStates implements Serializable{\r\n  \r\n  private static final long serialVersionUID = -329529021217842031L;\r\n\r\n  private Table<Integer, Pair<Integer,Integer>, Pair<Integer,Integer>> stockTable = HashBasedTable.create();\r\n  \r\n  private Table<Long, Integer,String> orderTable = HashBasedTable.create();\r\n  \r\n  private Table<Pair<Long,Integer>, Long,Integer> userTable = HashBasedTable.create();\r\n  \r\n  /**\r\n   * \r\n   * <p>hashBasedTable [modelId,Pair[attr1Id,attr2id],Pair[itemId,stock]]\r\n   * @return\r\n   */\r\n  public  Table<Integer, Pair<Integer,Integer>, Pair<Integer,Integer>> getStockTable(){\r\n    return stockTable;\r\n  }\r\n  \r\n  /**\r\n   * \r\n   * <p>hashBasedTable [orderId,status,coupon]\r\n   * @return\r\n   */\r\n  public Table<Long, Integer,String> getOrderTable(){\r\n    return orderTable;\r\n  }\r\n  \r\n  /**\r\n   * \r\n   * <p>hashBasedTable [Pair[uderId,modelId],orderId,status]\r\n   * @return\r\n   */\r\n  public  Table<Pair<Long,Integer>, Long,Integer> getUserTable(){\r\n    return userTable;\r\n  }\r\n  \r\n  \r\n \r\n  @Override\r\n  public String toString() {\r\n    return \"ItemStates [stockTable=\" + stockTable + \", orderTable=\" + orderTable + \", userTable=\"\r\n        + userTable + \"]\";\r\n  }\r\n\r\n  public static  ItemStates  create(){\r\n    return new ItemStates();\r\n  }\r\n\r\n}\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/EsotericSoftware/kryo/issues/comments/207642493","html_url":"https://github.com/EsotericSoftware/kryo/issues/373#issuecomment-207642493","issue_url":"https://api.github.com/repos/EsotericSoftware/kryo/issues/373","id":207642493,"user":{"login":"magro","id":64285,"avatar_url":"https://avatars.githubusercontent.com/u/64285?v=3","gravatar_id":"","url":"https://api.github.com/users/magro","html_url":"https://github.com/magro","followers_url":"https://api.github.com/users/magro/followers","following_url":"https://api.github.com/users/magro/following{/other_user}","gists_url":"https://api.github.com/users/magro/gists{/gist_id}","starred_url":"https://api.github.com/users/magro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magro/subscriptions","organizations_url":"https://api.github.com/users/magro/orgs","repos_url":"https://api.github.com/users/magro/repos","events_url":"https://api.github.com/users/magro/events{/privacy}","received_events_url":"https://api.github.com/users/magro/received_events","type":"User","site_admin":false},"created_at":"2016-04-08T23:08:28Z","updated_at":"2016-04-08T23:08:28Z","body":"Sorry for the late response, is this still relevant? "}}