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

Dependency information for qualified beans does not include qualified name, resulting in incorrect circular dependency detection #644

Closed
octylFractal opened this issue Jul 13, 2024 · 2 comments · Fixed by #645
Assignees
Labels
bug Something isn't working
Milestone

Comments

@octylFractal
Copy link

Given the following code:

// test/IncorrectCircularDependency.java
package test;

import io.avaje.inject.Bean;
import io.avaje.inject.Factory;
import jakarta.inject.Named;
import jakarta.inject.Singleton;

@Singleton
@Factory
public class IncorrectCircularDependency {
    @Bean
    @Named("parent") // for clarity, not necessary
    public String parent(@Named("child") String child) {
        throw new AssertionError("Method body unimportant");
    }

    @Bean
    @Named("child")
    public String child() {
        throw new AssertionError("Method body unimportant");
    }
}
// test/Test.java
package test;

import jakarta.inject.Inject;
import jakarta.inject.Singleton;

@Singleton
public class Test {
    private final String parent;

    @Inject
    public Test(@Named("parent") String parent) {
        this.parent = parent;
    }

    public String getParent() {
        return parent;
    }
}

Despite the clearly non-circular dependency from parent to child, due to the dependency of parent incorrectly not using the child qualifier and depending on itself, avaje-inject spits out this error:

error: Circular dependencies detected with beans [java.lang.String:parent, test.Test]  To handle circular dependencies consider using field injection rather than constructor injection on one of the dependencies. 
   See https://avaje.io/inject/#circular
error: Circular dependency - java.lang.String:parent dependsOn java.lang.String:parent for java.lang.String
error: Circular dependency - test.Test dependsOn java.lang.String:parent for java.lang.String

This should not be an error and should compile cleanly.

@SentryMan
Copy link
Collaborator

nice catch

@SentryMan SentryMan self-assigned this Jul 13, 2024
@SentryMan SentryMan added the bug Something isn't working label Jul 13, 2024
@SentryMan SentryMan added this to the 10.1 milestone Jul 13, 2024
@rbygrave
Copy link
Contributor

FYI 10.1 has been released @octylFractal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants