Skip to content

Commit

Permalink
Qualified injected fields must not be final
Browse files Browse the repository at this point in the history
- just get rid of an annoying warning
- resolves quarkusio#27198
  • Loading branch information
mkouba committed Aug 9, 2022
1 parent 8409f81 commit 0104d82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.logging.Logger;

import io.quarkus.arc.processor.AnnotationsTransformer;
Expand Down Expand Up @@ -69,7 +70,10 @@ public int getPriority() {
@Override
public void transform(TransformationContext ctx) {
Collection<AnnotationInstance> fieldAnnotations = ctx.getAnnotations();
if (Modifier.isStatic(ctx.getTarget().asField().flags()) || contains(fieldAnnotations, DotNames.INJECT)
FieldInfo field = ctx.getTarget().asField();
if (Modifier.isStatic(field.flags())
|| Modifier.isFinal(field.flags())
|| contains(fieldAnnotations, DotNames.INJECT)
|| contains(fieldAnnotations, DotNames.PRODUCES)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
Expand Down Expand Up @@ -35,18 +36,32 @@ public class AutoFieldInjectionTest {
public void testInjectionWorks() {
assertEquals("ok", bean.foo);
assertEquals(1l, bean.bar);
assertNull(Client.staticFoo);
assertNull(bean.baz);
}

@Dependent
static class Client {

// @Inject should not be added here
@MyQualifier
static String staticFoo;

// @Inject is added automatically
@MyQualifier
String foo;

@MyQualifier
Long bar;

// @Inject should not be added here
@MyQualifier
final Long baz;

Client() {
this.baz = null;
}

}

static class Producer {
Expand Down

0 comments on commit 0104d82

Please sign in to comment.