Skip to content

Commit

Permalink
Scheduler - detect scheduled methods of the same name on a class
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Mar 2, 2023
1 parent 9207c6b commit 431e43e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ public boolean isNonBlocking() {
return nonBlocking;
}

public String getMethodDescription() {
return method.declaringClass().name() + "#" + method.name() + "()";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;
Expand Down Expand Up @@ -192,17 +194,23 @@ void validateScheduledBusinessMethods(SchedulerConfig config, List<ScheduledBusi
ValidationPhaseBuildItem validationPhase, BuildProducer<ValidationErrorBuildItem> validationErrors) {
List<Throwable> errors = new ArrayList<>();
Map<String, AnnotationInstance> encounteredIdentities = new HashMap<>();
Set<String> methodDescriptions = new HashSet<>();

for (ScheduledBusinessMethodItem scheduledMethod : scheduledMethods) {
if (!methodDescriptions.add(scheduledMethod.getMethodDescription())) {
errors.add(new IllegalStateException("Multiple @Scheduled methods of the same name declared on the same class: "
+ scheduledMethod.getMethodDescription()));
continue;
}
MethodInfo method = scheduledMethod.getMethod();
if (Modifier.isAbstract(method.flags())) {
errors.add(new IllegalStateException("@Scheduled method must not be abstract: "
+ method.declaringClass().name() + "#" + method.name() + "()"));
+ scheduledMethod.getMethodDescription()));
continue;
}
if (Modifier.isPrivate(method.flags())) {
errors.add(new IllegalStateException("@Scheduled method must not be private: "
+ method.declaringClass().name() + "#" + method.name() + "()"));
+ scheduledMethod.getMethodDescription()));
continue;
}

Expand Down

0 comments on commit 431e43e

Please sign in to comment.