Patch for JRuby/Windows specific to this platform

Extract the fix from previous commit into a function.
Only patch for JRuby/Windows. Maybe MRI/Windows is also affected but we would need more input for that.