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

Arc Ignoring injected field #27198

Closed
Plawn opened this issue Aug 9, 2022 · 3 comments · Fixed by #27207
Closed

Arc Ignoring injected field #27198

Plawn opened this issue Aug 9, 2022 · 3 comments · Fixed by #27207
Assignees
Labels
area/arc Issue related to ARC (dependency injection) kind/bug Something isn't working
Milestone

Comments

@Plawn
Copy link

Plawn commented Aug 9, 2022

Describe the bug

When building the project we get the following warning:

[io.qua.arc.pro.Injection] (build-56) An injection field must be non-static and non-final - ignoring

with the given class

package //s.service;

package // omitted

import java.time.LocalDate;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.BadRequestException;
import //.GlobalConstants;
import //.KeycloackService;
import //r.BasicUserWithHistoriesDto;
import //.UserHistory;
import //.HistoryRepository;
import //.HistoryUpdateHandler;
import //.HttpCacheHandler;

@ApplicationScoped
@RequiredArgsConstructor(onConstructor = @__(@Inject))
@Slf4j
public class HistoryService {

    private final KeycloackService keycloackService;
    private final HistoryRepository historyRepository;

    @Named(GlobalConstants.POST_HISTORY_HANDLERS_NAME)
    private final List<HistoryUpdateHandler> historyHooks;

    private final HttpCacheHandler<Collection<BasicUserWithHistoriesDto>, Long> userHistoriesCache;


  // rest of the code omitted

}

and the given lombok conf

config.stopBubbling = true

lombok.addLombokGeneratedAnnotation = true

lombok.copyableAnnotations += javax.inject.Named

producing the given source:

// Generated by delombok at Tue Aug 09 11:28:41 CEST 2022
package // omitted

import java.time.LocalDate;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.BadRequestException;
import //.GlobalConstants;
import //.KeycloackService;
import //r.BasicUserWithHistoriesDto;
import //.UserHistory;
import //.HistoryRepository;
import //.HistoryUpdateHandler;
import //.HttpCacheHandler;

@ApplicationScoped
public class HistoryService {
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(HistoryService.class);
    private final KeycloackService keycloackService;
    private final HistoryRepository historyRepository;
    @Named(GlobalConstants.POST_HISTORY_HANDLERS_NAME)
    private final List<HistoryUpdateHandler> historyHooks;
    private final HttpCacheHandler<Collection<BasicUserWithHistoriesDto>, Long> userHistoriesCache;

   // rest of the code omitted
    @Inject
    @java.lang.SuppressWarnings("all")
    @lombok.Generated
    public HistoryService(final KeycloackService keycloackService, final HistoryRepository historyRepository, @Named(GlobalConstants.POST_HISTORY_HANDLERS_NAME) final List<HistoryUpdateHandler> historyHooks, final HttpCacheHandler<Collection<BasicUserWithHistoriesDto>, Long> userHistoriesCache) {
        this.keycloackService = keycloackService;
        this.historyRepository = historyRepository;
        this.historyHooks = historyHooks;
        this.userHistoriesCache = userHistoriesCache;
    }
}

Expected behavior

No warning as we use the constructor to inject the value in the field and not @Inject

Actual behavior

We get the warning

[io.qua.arc.pro.Injection] (build-56) An injection field must be non-static and non-final - ignoring

How to Reproduce?

  1. Use Quarkus 2.11.2.Final
  2. Use Lombok with the given configuration
  3. Build the project

Output of uname -a or ver

No response

Output of java -version

11

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.11.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

maven

Additional information

No response

@Plawn Plawn added the kind/bug Something isn't working label Aug 9, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Aug 9, 2022

/cc @manovotn, @mkouba

@quarkus-bot quarkus-bot bot added the area/arc Issue related to ARC (dependency injection) label Aug 9, 2022
@mkouba
Copy link
Contributor

mkouba commented Aug 9, 2022

So if I understand it correctly the lombok.copyableAnnotations results in the @Named(GlobalConstants.POST_HISTORY_HANDLERS_NAME) final List<HistoryUpdateHandler> historyHooks constructor parameter. This will confuse a feature called qualified injected fields. In short, if a non-static field is annoated with a qualifier (@Named in this particular case) then quarkus adds @Inject automatically. This allows for simpler injection points such as @ConfigProperty(name = "cool") bool coolProperty.

You can use the quarkus.arc.auto-inject-fields=false to disabled this feature for the moment.

I'm going to send a PR to exclude the final fields as well.

@mkouba mkouba self-assigned this Aug 9, 2022
@mkouba mkouba added this to the 2.12 - main milestone Aug 9, 2022
mkouba added a commit to mkouba/quarkus that referenced this issue Aug 9, 2022
- just get rid of an annoying warning
- resolves quarkusio#27198
mkouba added a commit to mkouba/quarkus that referenced this issue Aug 9, 2022
- just get rid of an annoying warning
- resolves quarkusio#27198
@Plawn
Copy link
Author

Plawn commented Aug 9, 2022

thanks !

miador pushed a commit to miador/quarkus that referenced this issue Sep 6, 2022
- just get rid of an annoying warning
- resolves quarkusio#27198
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants