Backport of fix for
https://issues.apache.org/bugzilla/show_bug.cgi?id=18813 from 2.1