[Libreoffice-bugs] [Bug 84237] Method setErrorHandler in DOM::CDocumentBuilder not working

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Fri Aug 11 08:07:28 UTC 2017


https://bugs.documentfoundation.org/show_bug.cgi?id=84237

--- Comment #5 from Fyodor <fyodor_e at hotmail.com> ---
In brief, this bug relates to UnitTests for unoxml module which are failing
with unhanded exception. In unittests we want to override this behavior by
calling setErrorHandler, which really doesn't work, as it not implemented. In
UnitTests there is custom struct ErrorHandler defined, which has warning, error
and fatalerror member functions. It's expected that these function called in
place of exception and if so, unittests will complete correctly.

But I think that such behaiviuor (calling error handler's functions in plase of
throwing exception) is not correct. Code in CDocumentBuilder class relates to
exceptions in it methods. For example, this is part from
CDocumentBuilder::parse method (starting from line 337 in file
unoxml/source/dom/documentbuilder.cxx)

// ------------------- C++ code starts ----------------------

xmlDocPtr const pDoc = xmlCtxtReadIO(pContext.get(), xmlIO_read_func,
xmlIO_close_func, &c, nullptr, nullptr, 0);
// Previous line calls xmlCtxtReadIO from libxml2 to parse xml
// If there is error in parsed xml, pDoc == nullptr - this means some error

if (pDoc == nullptr) {
// In case of error we throw exception and PASS CONTROL to first catch
statement
throwEx(pContext.get());
}

// If there is no error - we init XDocument and return it
Reference< XDocument > const xRet(CDocument::CreateCDocument(pDoc).get());
return xRet;

// ------------------- C++ code ends ----------------------

As seen, if we will not throw an exception, we should at least modify
CDocumentBuilder::parse to return nullptr and not try to init XDocument. Also
this can lead to modification of other code which is call
CDocumentBuilder::parse AND code which calls throwEx as it not throw exception
if custom error handler is set. As a result may be we'll should modify many
lines of code, and produce even more errors...

I suggest to remove setErrorHandler and catch exceptions in UnitTests. As a
result, unittests should complete as desired.

I'm novice in LO dev, so my suggestion can be wrong. I'll appreciate any
advice.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20170811/02022863/attachment.html>


More information about the Libreoffice-bugs mailing list