Java XML SAXParser 在方法 .parse(InputSource,XMLCommandsHandler) 上抛出 NullPointerException

发布于 2024-09-25 07:22:37 字数 576 浏览 4 评论 0原文

当使用 jdk 的 javax.xml.parsers.SAXParser 解析来自套接字的流时,我得到一个非常神秘的 NullPointerException 。

我的InputSource 是一个RecordingInputStream,它是我通过扩展FilterInputStream 创建的,以便能够在日志文件中记录我在套接字上接收到的所有数据,然后再将其发送到解析器。通过使用这种方式,我现在可以看到,当流中出现以下标记时,会专门抛出 NullPointerException:

<order act="D" order_id="16508679" scn="147185767940" reason="DELETE_ORDR" who_id="90296"/>

否则,流的解析工作正常。所有其他频繁出现的 XML 标记都已成功解析(不会引发异常),并且相应的 XMLCommandsHandler 方法也能正确调用。

请知道为什么会出现这个 NullPointerException 吗?否则,我将面临另一种选择:诅咒所有现成的 XML 流解析器,并编写我自己的简单解析器。厌倦了探索其他软件的错误或糟糕的设计:(

I get a very misterious NullPointerException when parsing a stream comming from a socket with jdk's javax.xml.parsers.SAXParser.

My InputSource is a RecordingInputStream that I created by extending FilterInputStream in order to be able to record in a log file all the data that I receive on the socket before it goes down to the parser. By using this way I can now see, that the NullPointerException is thrown specifically when the following tag appears in the stream:

<order act="D" order_id="16508679" scn="147185767940" reason="DELETE_ORDR" who_id="90296"/>

Otherwise the parsing of the stream is working okay. All other XML tags that frequently comes, get parsed successfuly (no exceptions are thrown), and corresponding XMLCommandsHandler's methods do get invoked correctly.

Please, any clue why this NullPointerException appears? Otherwise I'm facing the alternative to curse all ready-written XML stream parsers, and write my own simple parser. Tired of exploring other software's bugs, or poor design :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

落叶缤纷 2024-10-02 07:22:37

您可能想尝试 Xerces撒克逊.

You might want to try Xerces or Saxon.

南城旧梦 2024-10-02 07:22:37

我发现了错误。抱歉,我忘了发布我的答案,当时我真的被工作压垮了。我现在想起来了,我现在就回答一下。
这是我的代码中的空指针异常。 XMLCommandsHandler 正在调用的代码。当然,它与 SAX 解析器无关。

我的歉意。

I found the error. Sorry I forgot to post my answer back then I was realy overwhelmed with work. I remember now, and I answer it now.
It was a nullpointer exception in my code. Code that the XMLCommandsHandler is calling. Of course it had nothing to do with the SAX parser.

My appologies.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文