Skip to content

Commit

Permalink
disable producing a Guard/TypedGuard with an identifier of "global"
Browse files Browse the repository at this point in the history
This is to avoid a possible future collision when configuration
will apply to beans of type `Guard` / `TypedGuard`.
  • Loading branch information
Ladicek committed Nov 28, 2024
1 parent c62f073 commit 04a4c07
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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) {
}
}
Original file line number Diff line number Diff line change
@@ -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<String> GUARD = TypedGuard.create(String.class).build();
}
Original file line number Diff line number Diff line change
@@ -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) {
}
}

0 comments on commit 04a4c07

Please sign in to comment.