NullPointerException in XMLSAXHandler: locator is null

Description

When XMLSaxHandler is catching exceptions or the methods error(), fatalError() or warning() are called, it logs the column and line number using the locator object, which is a private field in XMLSAXHandler. In some environments such as Tomcat 5.0, the locator object is null (either never set or setDocumentLocator() is never called - I didn't track it down to this point). I assume this depends on the xml parsers registered here. The methods mentioned do not check this, resulting in NullPointerExceptions.

Fix:

Whereever the locator object is used, check it on null, and do not use it if it's null (see attached source).

I don't know if the standard DefaultHandler interface implemented here requires the setDocumentLocator() method to be always called with a non-null value. But I think it doesn't hurt to check on null to add robustness.

Environment

None

Status

Assignee

Unassigned

Reporter

codehaus

Triage

None

Components

Fix versions

Affects versions

2.2.M0
2.2.M1
2.2.M2
2.2-RC0
2.2-RC1
2.1.0
2.1.1

Priority

High
Configure