google-code-export / nutz

Automatically exported from code.google.com/p/nutz
Apache License 2.0
1 stars 1 forks source link

Json toJson()当传入的是HttpRequest时出错 #217

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
问题产生的条件:
使用Apache Common FileUpload

发生问题的调用代码:
传入的args为一个HttpRequest
    public static void save(String pre,Object...args){
        try{
            File file = new File(pre+System.currentTimeMillis()+".txt");
            FileWriter fw = new FileWriter(file);
            for (Object obj : args) {
                fw.write(Json.toJson(obj));
                fw.write("\n");
            }
            fw.flush();
            fw.close();
        }catch (Throwable e) {
            e.printStackTrace();
        }
    }

问题的详细说明:
内存溢出.

异常堆栈:
java.util.ConcurrentModificationException
    at
java.util.LinkedHashMap$LinkedHashIterator.nextEntry(LinkedHashMap.java:373)
    at java.util.LinkedHashMap$KeyIterator.next(LinkedHashMap.java:384)
    at org.nutz.json.JsonRendering.map2Json(JsonRendering.java:116)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:233)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.map2Json(JsonRendering.java:124)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:233)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.map2Json(JsonRendering.java:124)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:233)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.map2Json(JsonRendering.java:124)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:233)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.Json.toJson(Json.java:133)
    at org.nutz.json.Json.toJson(Json.java:103)
    at org.nutz.json.Json.toJson(Json.java:89)
    at com.XXXXX.protal.common.SaveObject2Txt.save(Unknown Source)
    at com.XXXXX.protal.common.FileUploadHandler.handle(Unknown Source)
    at com.XXXXX.protal.common.ResumeUploadServlet.doPost(Unknown Source)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilt
erChain.java:290)
    at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.
java:206)
    at
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(Characte
rEncodingFilter.java:96)
    at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilte
r.java:76)
    at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilt
erChain.java:235)
    at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.
java:206)
    at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:2
33)
    at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:1
91)
    at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109
)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Pr
otocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)

相关日志:
java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:2882)
    at
java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
    at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:572)
    at java.lang.StringBuilder.append(StringBuilder.java:203)
    at org.nutz.lang.stream.StringWriter.write(StringWriter.java:23)
    at java.io.Writer.write(Writer.java:175)
    at java.io.Writer.write(Writer.java:140)
    at java.io.Writer.append(Writer.java:210)
    at org.nutz.json.JsonRendering.appendPairBegin(JsonRendering.java:64)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:72)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.coll2Json(JsonRendering.java:264)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:235)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.map2Json(JsonRendering.java:124)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:233)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.map2Json(JsonRendering.java:124)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:233)
    at org.nutz.json.JsonRendering.appendPair(JsonRendering.java:75)
    at org.nutz.json.JsonRendering.pojo2Json(JsonRendering.java:161)
    at org.nutz.json.JsonRendering.render(JsonRendering.java:240)

com.XXXXX.protal.common 为一些客户代码.即 发生问题的调用代码

Original issue reported on code.google.com by wendal1985@gmail.com on 4 Jun 2010 at 4:14

GoogleCodeExporter commented 9 years ago
fixed in r1292

Original comment by zozoh...@gmail.com on 4 Jun 2010 at 7:48

GoogleCodeExporter commented 9 years ago
应该是 Map 没有做记录,所以重复输出

Original comment by zozoh...@gmail.com on 4 Jun 2010 at 7:49

GoogleCodeExporter commented 9 years ago
恩, 晚点再放到项目中测试一下.

Original comment by wendal1985@gmail.com on 4 Jun 2010 at 8:01