Fix two error paths that failed on their own - #615
Open
JakeHuneau wants to merge 1 commit into
Open
JakeHuneau wants to merge 1 commit into
JakeHuneau wants to merge 1 commit into
Conversation
IOUtil.handleArchive moves a file into the error directory after its message has already failed. It built its failure message out of the destination file, which is still null when it was working out the archive directory that failed. That is exactly what happens when the error directory cannot be created, on a read only or unavailable mount for instance, so the handler threw a NullPointerException that replaced the real cause. Being unchecked it also travelled past the callers that catch OpenAS2Exception. It now names the directory it was given when it never got as far as a destination. ViewMessageCommand and GetDataForCharts checked for having no message tracking module, built the error result for it and then dropped it without returning, so execution carried on and used the empty list anyway. Neither reported the problem: both failed with an IndexOutOfBoundsException instead, since getModulesSupportingAction always returns a list and never null. The two sibling commands that make the same check, ListMessagesCommand and GetMdnPathCommand, already return, so this brings the other two into line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two places whose job is to report a problem fail while doing it, so the original problem is lost.
handleArchive throws a NullPointerException instead of reporting
IOUtil.handleArchivemoves a file into the error directory after its message has already failed:getDirectoryFilecallscreateDirs, which throwsIOException("Directory '...' cannot be created")when the directory cannot be created: a read only mount, a permissions problem, or a network share that is temporarily unavailable. At that pointdestFilehas not been assigned, so building the message throws aNullPointerException.Two consequences. The real cause is replaced by a bare NPE, in the handler that runs after something has already gone wrong, which is the worst place to lose a diagnostic. And an NPE is unchecked, so it travels past the four callers in the directory poller and the resender that catch
OpenAS2Exception.It now names the directory it was given when it never got as far as a destination.
Two commands discard the error they just built
ViewMessageCommandandGetDataForCharts:The result is built and dropped, execution continues, and
mpl.get(0)runs on the empty list.getModulesSupportingActionalways returns a list and never null, so the failure is anIndexOutOfBoundsExceptionrather than the NPE the shape of the guard suggests. Anyone runningmessages viewor requesting the charts on a deployment without the database tracking module gets a stack trace instead of "No DB tracking module available."ListMessagesCommandandGetMdnPathCommandmake the same check and already return, so this brings the other two into line with them.Testing
184 tests pass, 4 new for the archive handler. Restoring the null dereference fails 3 of the 4.
The reproduction uses a regular file as a parent path component so that creating the archive directory fails on any platform and as any user including root, rather than relying on a read only directory, which a privileged user would ignore and quietly skip the test. There is a separate read only case as well, guarded by assumptions.