Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable producing a Guard / TypedGuard with an identifier of global #1091

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -12,7 +12,7 @@

@FaultToleranceBasicTest
@WithSystemProperty(key = "smallrye.faulttolerance.global.retry.max-retries", value = "7")
@WithSystemProperty(key = "smallrye.faulttolerance.\"io.smallrye.faulttolerance.config.better.BeanWithRetry\".retry.max-retries", value = "5")
@WithSystemProperty(key = "smallrye.faulttolerance.\"io.smallrye.faulttolerance.config.better.ConfigPropertyBean\".retry.max-retries", value = "5")
public class ConfigPropertyGlobalVsClassTest {
@Inject
private ConfigPropertyBean bean;
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) {
}
}