vpelikh commented on code in PR #4230:
URL: https://github.com/apache/logging-log4j2/pull/4230#discussion_r4056572724
##########
log4j-core/src/main/java/org/apache/logging/log4j/core/config/OrderComparator.java:
##########
@@ -39,20 +41,32 @@ public static Comparator<Class<?>> getInstance() {
@Override
public int compare(final Class<?> lhs, final Class<?> rhs) {
- final Order lhsOrder = Objects.requireNonNull(lhs,
"lhs").getAnnotation(Order.class);
- final Order rhsOrder = Objects.requireNonNull(rhs,
"rhs").getAnnotation(Order.class);
- if (lhsOrder == null && rhsOrder == null) {
+ Objects.requireNonNull(lhs, "lhs");
+ Objects.requireNonNull(rhs, "rhs");
+ final OptionalInt lhsOrder = getOrder(lhs);
+ final OptionalInt rhsOrder = getOrder(rhs);
+ if (lhsOrder.isEmpty() && rhsOrder.isEmpty()) {
// both unannotated means equal priority
return 0;
}
- // if only one class is @Order-annotated, then prefer that one
- if (rhsOrder == null) {
+ // if only one class is annotated, then prefer that one
+ if (rhsOrder.isEmpty()) {
return -1;
}
- if (lhsOrder == null) {
+ if (lhsOrder.isEmpty()) {
return 1;
}
- // larger value means higher priority
- return Integer.signum(rhsOrder.value() - lhsOrder.value());
+ // larger value means higher priority (descending order)
+ return Integer.signum(rhsOrder.getAsInt() - lhsOrder.getAsInt());
+ }
+
+ private static OptionalInt getOrder(final Class<?> clazz) {
+ // Check for legacy @Order annotation first
+ final Order order = clazz.getAnnotation(Order.class);
+ if (order != null) {
+ return OptionalInt.of(order.value());
+ }
+ // Fall back to @Ordered via AnnotationUtil
+ return AnnotationUtil.getOrder(clazz);
Review Comment:
Addressed: kept factories on `@Ordered`; added `OrderComparatorTest` in
log4j-core-test pinning the `@Ordered` direction and the `@Order`/`@Ordered`
fallback. If you prefer the ascending `@Ordered` convention, it is a small
comparator change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]