开发者

for loop in HttpServer misbehaves

I have this weird problem with a for loop. This loop only iterates once while it should iterate more times (it has 3-4 elements in it, depending on something irrelevant.

Here is the code:

System.out.println("Executing " + url);
System.out.println("_elements.size()=" + _elements.size());
for (Object el : _elements) {
        System.out.println("element class:" + el.getClass().getName());
        if (el instanceof DynamicServlet) {
            ((DynamicServlet) el).execute();
            _stringBuff.append(((DynamicServlet) el).getOutput());
            }
        if (el instanceof String)
            _stringBuff.append((String)el);
} // for

System.out.println("finished for loop");

The program prints the following lines:

Executing /admin.dsp

_elements.size()=4

element class:java.lang.String

Notice that it never ge开发者_开发技巧ts to print the last System.out.println! It mysteriously breaks and exits. There is no Exception thrown or anything, and this code section is being by the "handle(HttpExchange)" method of com.sun.net.httpserver.HttpHandler.

Does anyone have any idea what's going on here?

Thanks in advance!


Do you know that no exception is being thrown ? Or simply that no exception is being reported ? I would wrap the contents of the iterator block in a try/catch and report any exceptions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜