Skip to content

Commit 72e23e5

Browse files
authored
Merge pull request quarkusio#36104 from Ladicek/fix-duplicate-circuit-breaker-name-detection
Fix duplicate circuit breaker name detection
2 parents c8d4533 + 5db67ac commit 72e23e5

File tree

11 files changed

+73
-18
lines changed

11 files changed

+73
-18
lines changed

extensions/smallrye-fault-tolerance/deployment/src/main/java/io/quarkus/smallrye/faulttolerance/deployment/FaultToleranceScanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ boolean hasFTAnnotations(ClassInfo clazz) {
8080
void forEachMethod(ClassInfo clazz, Consumer<MethodInfo> action) {
8181
for (MethodInfo method : clazz.methods()) {
8282
if (method.name().startsWith("<")) {
83-
// constructors (or static init blocks) can't be intercepted
83+
// constructors and static inititalizers can't be intercepted
8484
continue;
8585
}
8686
if (method.isSynthetic()) {

extensions/smallrye-fault-tolerance/deployment/src/main/java/io/quarkus/smallrye/faulttolerance/deployment/SmallRyeFaultToleranceProcessor.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.jboss.jandex.ClassInfo;
2525
import org.jboss.jandex.DotName;
2626
import org.jboss.jandex.IndexView;
27-
import org.jboss.jandex.MethodInfo;
2827

2928
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
3029
import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem;
@@ -279,6 +278,7 @@ void processFaultToleranceAnnotations(SmallRyeFaultToleranceRecorder recorder,
279278

280279
List<FaultToleranceMethod> ftMethods = new ArrayList<>();
281280
List<Throwable> exceptions = new ArrayList<>();
281+
Map<String, Set<String>> existingCircuitBreakerNames = new HashMap<>();
282282

283283
for (BeanInfo info : validationPhase.getContext().beans()) {
284284
ClassInfo beanClass = info.getImplClazz();
@@ -319,6 +319,12 @@ void processFaultToleranceAnnotations(SmallRyeFaultToleranceRecorder recorder,
319319
reflectiveClass.produce(ReflectiveClassBuildItem.builder(exceptionNames.get()).build());
320320
}
321321
}
322+
323+
if (annotationStore.hasAnnotation(method, DotNames.CIRCUIT_BREAKER_NAME)) {
324+
AnnotationInstance ann = annotationStore.getAnnotation(method, DotNames.CIRCUIT_BREAKER_NAME);
325+
existingCircuitBreakerNames.computeIfAbsent(ann.value().asString(), ignored -> new HashSet<>())
326+
.add(method + " @ " + method.declaringClass());
327+
}
322328
}
323329
});
324330

@@ -337,16 +343,6 @@ void processFaultToleranceAnnotations(SmallRyeFaultToleranceRecorder recorder,
337343

338344
recorder.createFaultToleranceOperation(ftMethods);
339345

340-
// since annotation transformations are applied lazily, we can't know
341-
// all transformed `@CircuitBreakerName`s and have to rely on Jandex here
342-
Map<String, Set<String>> existingCircuitBreakerNames = new HashMap<>();
343-
for (AnnotationInstance it : index.getAnnotations(DotNames.CIRCUIT_BREAKER_NAME)) {
344-
if (it.target().kind() == Kind.METHOD) {
345-
MethodInfo method = it.target().asMethod();
346-
existingCircuitBreakerNames.computeIfAbsent(it.value().asString(), ignored -> new HashSet<>())
347-
.add(method + " @ " + method.declaringClass());
348-
}
349-
}
350346
for (Map.Entry<String, Set<String>> entry : existingCircuitBreakerNames.entrySet()) {
351347
if (entry.getValue().size() > 1) {
352348
exceptions.add(new DefinitionException("Multiple circuit breakers have the same name '"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.inheritance;
1+
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.duplicate;
22

33
import jakarta.inject.Singleton;
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.inheritance;
1+
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.duplicate;
22

33
import jakarta.inject.Singleton;
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.inheritance;
1+
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.duplicate;
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertTrue;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.duplicate;
1+
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.inheritance;
22

33
import static org.junit.jupiter.api.Assertions.assertNotNull;
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.duplicate;
1+
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.inheritance;
22

33
import jakarta.inject.Singleton;
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.duplicate;
1+
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.inheritance;
22

33
import jakarta.inject.Singleton;
44

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.noduplicate;
2+
3+
import jakarta.inject.Singleton;
4+
5+
import org.eclipse.microprofile.faulttolerance.CircuitBreaker;
6+
7+
import io.smallrye.faulttolerance.api.CircuitBreakerName;
8+
9+
@Singleton
10+
public class CircuitBreakerService1 {
11+
@CircuitBreaker
12+
@CircuitBreakerName("hello")
13+
public String hello() {
14+
return "1";
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.quarkus.smallrye.faulttolerance.test.circuitbreaker.maintenance.noduplicate;
2+
3+
import org.eclipse.microprofile.faulttolerance.CircuitBreaker;
4+
5+
import io.smallrye.faulttolerance.api.CircuitBreakerName;
6+
7+
public class CircuitBreakerService2 {
8+
// this class is not a bean, so there's no circuit breaker and hence no duplicate circuit breaker name
9+
@CircuitBreaker
10+
@CircuitBreakerName("hello")
11+
public String hello() {
12+
return "2";
13+
}
14+
}

0 commit comments

Comments
 (0)