diff --git a/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/CdiLogger.java b/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/CdiLogger.java index f2e363ce..88dca106 100644 --- a/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/CdiLogger.java +++ b/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/CdiLogger.java @@ -53,4 +53,7 @@ interface CdiLogger extends BasicLogger { @Message(id = 9, value = "Guard/TypedGuard with identifier '%s' expected, but does not exist") DefinitionException expectedGuardDoesNotExist(String identifier); + + @Message(id = 10, value = "Guard/TypedGuard with identifier 'global' is not allowed: %s") + DefinitionException guardWithIdentifierGlobal(String bean); } diff --git a/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/FaultToleranceExtension.java b/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/FaultToleranceExtension.java index e902710b..0a4e05ca 100644 --- a/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/FaultToleranceExtension.java +++ b/implementation/fault-tolerance/src/main/java/io/smallrye/faulttolerance/FaultToleranceExtension.java @@ -320,9 +320,11 @@ void processBean(@Observes ProcessBean pb) { if (isGuard) { for (Annotation ann : bean.getQualifiers()) { if (ann instanceof Identifier) { - existingGuards - .computeIfAbsent(((Identifier) ann).value(), ignored -> new HashSet<>()) - .add(bean.toString()); + String id = ((Identifier) ann).value(); + existingGuards.computeIfAbsent(id, ignored -> new HashSet<>()).add(bean.toString()); + if ("global".equals(id)) { + pb.addDefinitionError(LOG.guardWithIdentifierGlobal(bean.toString())); + } } } } diff --git a/testsuite/basic/src/test/java/io/smallrye/faulttolerance/reuse/errors/GuardWithIdentifierGlobalProducer.java b/testsuite/basic/src/test/java/io/smallrye/faulttolerance/reuse/errors/GuardWithIdentifierGlobalProducer.java new file mode 100644 index 00000000..81b7fd6f --- /dev/null +++ b/testsuite/basic/src/test/java/io/smallrye/faulttolerance/reuse/errors/GuardWithIdentifierGlobalProducer.java @@ -0,0 +1,14 @@ +package io.smallrye.faulttolerance.reuse.errors; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; + +import io.smallrye.common.annotation.Identifier; +import io.smallrye.faulttolerance.api.Guard; + +@ApplicationScoped +public class GuardWithIdentifierGlobalProducer { + @Produces + @Identifier("global") + public static Guard GUARD = Guard.create().build(); +} diff --git a/testsuite/basic/src/test/java/io/smallrye/faulttolerance/reuse/errors/GuardWithIdentifierGlobalTest.java b/testsuite/basic/src/test/java/io/smallrye/faulttolerance/reuse/errors/GuardWithIdentifierGlobalTest.java new file mode 100644 index 00000000..05f67e97 --- /dev/null +++ b/testsuite/basic/src/test/java/io/smallrye/faulttolerance/reuse/errors/GuardWithIdentifierGlobalTest.java @@ -0,0 +1,16 @@ +package io.smallrye.faulttolerance.reuse.errors; + +import jakarta.enterprise.inject.spi.DefinitionException; + +import org.junit.jupiter.api.Test; + +import io.smallrye.faulttolerance.util.ExpectedDeploymentException; +import io.smallrye.faulttolerance.util.FaultToleranceBasicTest; + +@FaultToleranceBasicTest +@ExpectedDeploymentException(DefinitionException.class) +public class GuardWithIdentifierGlobalTest { + @Test + public void test(GuardWithIdentifierGlobalProducer ignored) { + } +} diff --git a/testsuite/basic/src/test/java/io/smallrye/faulttolerance/reuse/errors/TypedGuardWithIdentifierGlobalProducer.java b/testsuite/basic/src/test/java/io/smallrye/faulttolerance/reuse/errors/TypedGuardWithIdentifierGlobalProducer.java new file mode 100644 index 00000000..bd3d80fe --- /dev/null +++ b/testsuite/basic/src/test/java/io/smallrye/faulttolerance/reuse/errors/TypedGuardWithIdentifierGlobalProducer.java @@ -0,0 +1,14 @@ +package io.smallrye.faulttolerance.reuse.errors; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; + +import io.smallrye.common.annotation.Identifier; +import io.smallrye.faulttolerance.api.TypedGuard; + +@ApplicationScoped +public class TypedGuardWithIdentifierGlobalProducer { + @Produces + @Identifier("global") + public static TypedGuard GUARD = TypedGuard.create(String.class).build(); +} diff --git a/testsuite/basic/src/test/java/io/smallrye/faulttolerance/reuse/errors/TypedGuardWithIdentifierGlobalTest.java b/testsuite/basic/src/test/java/io/smallrye/faulttolerance/reuse/errors/TypedGuardWithIdentifierGlobalTest.java new file mode 100644 index 00000000..7e16abff --- /dev/null +++ b/testsuite/basic/src/test/java/io/smallrye/faulttolerance/reuse/errors/TypedGuardWithIdentifierGlobalTest.java @@ -0,0 +1,16 @@ +package io.smallrye.faulttolerance.reuse.errors; + +import jakarta.enterprise.inject.spi.DefinitionException; + +import org.junit.jupiter.api.Test; + +import io.smallrye.faulttolerance.util.ExpectedDeploymentException; +import io.smallrye.faulttolerance.util.FaultToleranceBasicTest; + +@FaultToleranceBasicTest +@ExpectedDeploymentException(DefinitionException.class) +public class TypedGuardWithIdentifierGlobalTest { + @Test + public void test(TypedGuardWithIdentifierGlobalProducer ignored) { + } +}