I think the sorting is unnecessary, because internalPostProcessors has been sorted in every previous stage of traversing ppNames.
Secondly, this sorting will break some rules, For example, it will cause nonOrderedPostProcessors to sort by @Order. But in JavaDoc of BeanPostProcessor ,this is not allowed.
The Ordering section of the class-level Javadoc for BeanPostProcessor states the following.
BeanPostProcessorbeans that are autodetected in anApplicationContextwill be ordered according toPriorityOrderedandOrderedsemantics. In contrast,BeanPostProcessorbeans that are registered programmatically with aBeanFactorywill be applied in the order of registration; any ordering semantics expressed through implementing thePriorityOrderedorOrderedinterface will be ignored for programmatically registered post-processors. Furthermore, the@Orderannotation is not taken into account forBeanPostProcessorbeans.
Comment From: snicoll
@chenqimiao thanks for the PR but we'd like to keep this as is. Please also review this note on the class you've modified.