Adding code from a patch offered in this bug report: https://bugs.eclipse.org/bugs/show_bug.cgi?id=234509