Bugfix 12602

Note: this is based on branch bugfix-12225, which should be merged before this one.