我从IDE中启动Grails2.1.5应用程序,其中设置了NumberFormatException的异常断点(这意味着每当抛出此异常时,应用程序就会中断)。
如果然后从Grails控制台执行以下代码:
import groovy.util.*
import groovyx.net.http.*
def uri = 'http://ws.audioscrobbler.com/2.0/?artist=Yelle&mbid=f43d43c8-eedf-4628-99b0-04120e7124c8&method=artist.gettopalbums&api_key=6e331f856413a5e3dfc91ec41cea5415&limit=6'
XmlSlurper().parse(uri)由于Long.parseLong中的以下代码,异常断点被触发
public static long parseLong(String s, int radix)
throws NumberFormatException
{
if (s == null) {
throw new NumberFormatException("null");
}
// rest of method omitted
}然而,XmlSlurper().parse(uri)似乎返回了预期的值,所以我猜这个异常是在某个地方处理的,但是我不知道在哪里。我不明白为什么调用Long.parseLong时第一个param的值为空。这是XmlSlurper中的一个bug,还是一些奇怪的实现细节?
更新
按照要求,这是调用堆栈。我使用的是JDK 7和Groovy 1.8.8。我自己试过调试它,但是正如您所看到的,我丢失了很多相关的源文件。
at java.lang.Long.parseLong(Long.java:404)
at java.lang.Long.parseLong(Long.java:483)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1571)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source:-1)
at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source:-1)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source:-1)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source:-1)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source:-1)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source:-1)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source:-1)
at groovy.util.XmlSlurper.parse(XmlSlurper.java:146)
at groovy.util.XmlSlurper.parse(XmlSlurper.java:212)发布于 2013-07-31 10:33:35
据我所知,这个文件来自OpenJDK汞存储库是Java 7更新25中sun.net.www.protocol.http.HttpURLConnection的版本,相关的摘录是
1570 try {
1571 cl = Long.parseLong(responses.findValue("content-length"));
1572 } catch (Exception exc) { };因此,当HTTP响应没有Content-Length头时,就会抛出(并立即忽略)Content-Length。
https://stackoverflow.com/questions/17955116
复制相似问题