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.

BeanPostProcessor beans that are autodetected in an ApplicationContext will be ordered according to PriorityOrdered and Ordered semantics. In contrast, BeanPostProcessor beans that are registered programmatically with a BeanFactory will be applied in the order of registration; any ordering semantics expressed through implementing the PriorityOrdered or Ordered interface will be ignored for programmatically registered post-processors. Furthermore, the @Order annotation is not taken into account for BeanPostProcessor beans.

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.