Skip to content

Commit 431e43e

Browse files
committed
Scheduler - detect scheduled methods of the same name on a class
- fix #31547
1 parent 9207c6b commit 431e43e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

extensions/scheduler/deployment/src/main/java/io/quarkus/scheduler/deployment/ScheduledBusinessMethodItem.java

+4
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ public boolean isNonBlocking() {
4848
return nonBlocking;
4949
}
5050

51+
public String getMethodDescription() {
52+
return method.declaringClass().name() + "#" + method.name() + "()";
53+
}
54+
5155
}

extensions/scheduler/deployment/src/main/java/io/quarkus/scheduler/deployment/SchedulerProcessor.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
import java.time.ZoneId;
1313
import java.util.ArrayList;
1414
import java.util.HashMap;
15+
import java.util.HashSet;
1516
import java.util.List;
1617
import java.util.Map;
1718
import java.util.Optional;
19+
import java.util.Set;
1820
import java.util.concurrent.CompletableFuture;
1921
import java.util.concurrent.CompletionStage;
2022
import java.util.function.Function;
@@ -192,17 +194,23 @@ void validateScheduledBusinessMethods(SchedulerConfig config, List<ScheduledBusi
192194
ValidationPhaseBuildItem validationPhase, BuildProducer<ValidationErrorBuildItem> validationErrors) {
193195
List<Throwable> errors = new ArrayList<>();
194196
Map<String, AnnotationInstance> encounteredIdentities = new HashMap<>();
197+
Set<String> methodDescriptions = new HashSet<>();
195198

196199
for (ScheduledBusinessMethodItem scheduledMethod : scheduledMethods) {
200+
if (!methodDescriptions.add(scheduledMethod.getMethodDescription())) {
201+
errors.add(new IllegalStateException("Multiple @Scheduled methods of the same name declared on the same class: "
202+
+ scheduledMethod.getMethodDescription()));
203+
continue;
204+
}
197205
MethodInfo method = scheduledMethod.getMethod();
198206
if (Modifier.isAbstract(method.flags())) {
199207
errors.add(new IllegalStateException("@Scheduled method must not be abstract: "
200-
+ method.declaringClass().name() + "#" + method.name() + "()"));
208+
+ scheduledMethod.getMethodDescription()));
201209
continue;
202210
}
203211
if (Modifier.isPrivate(method.flags())) {
204212
errors.add(new IllegalStateException("@Scheduled method must not be private: "
205-
+ method.declaringClass().name() + "#" + method.name() + "()"));
213+
+ scheduledMethod.getMethodDescription()));
206214
continue;
207215
}
208216

0 commit comments

Comments
 (0)