title: Gson throws MalformedJsonException, and other Exceptions
body: <p>I tried to save data to json string in a txt file using Gson and then restore it using Gson either. Things go well if I do it in eclipse. But when packaged to jar, Gson throws Exceptions.</p>
  
  <p>Here is the code for saving the file.</p>
  
  <pre><code>String gsonStr = gson.toJson(masterShips);  // masterShips is ArrayList&lt;Ship&gt;
  BufferedWriter writer = null;
  try {
      writer = new BufferedWriter(new FileWriter("D:\\master_ship.txt"));
      writer.write(gsonStr);
  } catch (IOException e) {
      System.err.println(e);
  } finally {
      if (writer != null) {
          try {
              writer.close();
          } catch (IOException e) {
              System.err.println(e);
          }
      }
  }
  </code></pre>
  
  <p>Then I read the file in eclipse using this code (and it works):</p>
  
  <pre><code>Scanner in = new Scanner(new FileReader("D:\\master_ship.txt"));
  
  String str = in.nextLine();
  Log.toDebug(str);
  in.close();
  JsonParser parser = new JsonParser();
  JsonElement je = parser.parse(str);
  JsonArray ja = je.getAsJsonArray();
  for (int i=0; i&lt;ja.size(); ++i) { 
      ... 
  }
  </code></pre>
  
  <p>But after packaged into jar and run in cmd, Exception occurs:</p>
  
  <pre><code>Exception in thread "main" com.google.gson.JsonSyntaxException: com.google.gson.
  stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malform
  ed JSON at line 1 column 4
          at com.google.gson.JsonParser.parse(JsonParser.java:65)
          at com.google.gson.JsonParser.parse(JsonParser.java:45)
          at kan.util.Master.loadMasterShip(Master.java:44)
          at kan.util.Master.load(Master.java:27)
          at kan.Main.main(Main.java:22)
  Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLeni
  ent(true) to accept malformed JSON at line 1 column 4
          at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1505)
          at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1386)
          at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:531)
          at com.google.gson.stream.JsonReader.peek(JsonReader.java:414)
          at com.google.gson.JsonParser.parse(JsonParser.java:60)
          ... 4 more
  </code></pre>
  
  <p>According to the hint of the Exception, I changed my code and it still works in eclipse:</p>
  
  <pre><code>Scanner in = new Scanner(new FileReader("D:\\master_ship.txt"));
  
  String str = in.nextLine();
  in.close();
  
  Reader reader = new StringReader(str);
  JsonReader jr = new JsonReader(reader);
  jr.setLenient(true);
  JsonParser parser = new JsonParser();
  JsonElement je = parser.parse(jr);
  JsonArray ja = je.getAsJsonArray();
  for (int i=0; i&lt;ja.size(); ++i) { 
  ... 
  }
  </code></pre>
  
  <p>But jar failed and throws </p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalStateException: This is not a JSON A
  rray.
      at com.google.gson.JsonElement.getAsJsonArray(JsonElement.java:106)
      at kan.util.Master.loadMasterShip(Master.java:58)
      at kan.util.Master.load(Master.java:30)
      at kan.Main.main(Main.java:22)
  </code></pre>
  
  <p><strong>As suggested by Sotirios I cut the length of the arraylist down, and when I increase the number of ships to 4, things go wrong. Here is the json:</strong></p>
  
  <pre><code>[{"id":1,"name":"睦月","type":2,"rank":2,"fuelMax":15,"bulletMax":15,"slotNum":2,"speed":10,"afterLv":20,"afterId":254,"range":1,"powerups":[1,1,0,0]},{"id":2,"name":"如月","type":2,"rank":1,"fuelMax":15,"bulletMax":15,"slotNum":2,"speed":10,"afterLv":20,"afterId":255,"range":1,"powerups":[0,1,0,0]},{"id":6,"name":"長月","type":2,"rank":1,"fuelMax":15,"bulletMax":15,"slotNum":2,"speed":10,"afterLv":20,"afterId":258,"range":1,"powerups":[0,1,0,0]},{"id":7,"name":"三日月","type":2,"rank":1,"fuelMax":15,"bulletMax":15,"slotNum":2,"speed":10,"afterLv":20,"afterId":260,"range":1,"powerups":[0,1,0,0]}]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ↑ colunm 473
  
  Exception in thread "main" com.google.gson.JsonSyntaxException: com.google.gson.
  stream.MalformedJsonException: Unterminated object at line 1 column 473
          at com.google.gson.internal.Streams.parse(Streams.java:56)
          at com.google.gson.JsonParser.parse(JsonParser.java:84)
          at kan.util.Master.loadMasterShip(Master.java:55)
          at kan.util.Master.load(Master.java:30)
          at kan.Main.main(Main.java:22)
  Caused by: com.google.gson.stream.MalformedJsonException: Unterminated object at
   line 1 column 473
          at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1505)
          at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:480)
          at com.google.gson.stream.JsonReader.hasNext(JsonReader.java:403)
          at com.google.gson.internal.bind.TypeAdapters$25.read(TypeAdapters.java:
  666)
          at com.google.gson.internal.bind.TypeAdapters$25.read(TypeAdapters.java:
  659)
          at com.google.gson.internal.bind.TypeAdapters$25.read(TypeAdapters.java:
  642)
          at com.google.gson.internal.Streams.parse(Streams.java:44)
          ... 4 more
  </code></pre>
  
  <p>Can anyone help me with this, you will be reaally preciated!</p>