FairyProject / fairy

Fairy is a compat & open-sourced Framework made with love <3
MIT License
62 stars 10 forks source link

InjectableComponent on methods not working properly #169

Open maurxce opened 1 month ago

maurxce commented 1 month ago
@Configuration
public class DependencyProvider {

    @InjectableComponent
    public PlaceholderHook createPlaceholderHook() {
        //return isEnabled("PlaceholderAPI") ? new PlaceholderHook() : null;
        return new PlaceholderHook();
    }

    private boolean isEnabled(String plugin) {
        return Bukkit.getPluginManager().isPluginEnabled(plugin);
    }
}
[18:14:27] [Server thread/ERROR]: [Fairy] java.lang.IllegalStateException: Failed to create configuration instance.
[18:14:27] [Server thread/INFO]: [ERROR] !-------------------!
[18:14:27] [Server thread/INFO]: [ERROR] An error was reported with Fairy container system!!
[18:14:27] [Server thread/INFO]: [ERROR] Node: Opdrachten
[18:14:27] [Server thread/INFO]: [ERROR] Component: md.schorn.opdrachten.utility.Processor
[18:14:27] [Server thread/INFO]: [ERROR]  
[18:14:27] [Server thread/INFO]: [ERROR] Messages:
[18:14:27] [Server thread/INFO]: [ERROR] >    Unknown dependency: md.schorn.opdrachten.dependency.PlaceholderHook
[18:14:27] [Server thread/INFO]: [ERROR] >     
[18:14:27] [Server thread/INFO]: [ERROR] >    Maybe you forgot to register it? Make sure the dependency is marked as @InjectableComponent
[18:14:27] [Server thread/INFO]: [ERROR] >    and you have the class in the classpath.
[18:14:27] [Server thread/ERROR]: Error occurred while enabling Opdrachten v0.0.9 (Is it up to date?)
java.lang.IllegalArgumentException: The DependencyTree wasn't resolved.

This does not happen when I annotate the PlaceholderHook class directly, but I can't do that since PlaceholderAPI is a softdepend

maurxce commented 1 month ago

If I annotate the PlaceholderHook class directly, I get the error mentioned in https://github.com/FairyProject/fairy/issues/168

maurxce commented 1 month ago

This was a follow-up issue, seemingly caused by #168 Annotating methods works fine.

maurxce commented 3 weeks ago

This time the problem happened with an empty constructor.

@Configuration
public class DependencyProvider {

    @InjectableComponent
    public PlaceholderWrapper createPlaceholderWrapper() {
        return new PlaceholderWrapper();
    }
}

It seems as if all my @Configurations just broke overnight

Edit: I didn't notice that I used the same example class as when I created the issue. This also happened with other configurations, but seems to work if classes get annotated directly

@Configuration
public class ItemProvider {

    @InjectableComponent
    public ItemFactory createItemFactory(Processor processor) {
        return new ItemFactory(processor);
    }
}
@Configuration
public class ProcessorProvider {

    @InjectableComponent
    public Processor createProcessor(PlaceholderWrapper placeholderWrapper) {
        return new Processor(placeholderWrapper);
    }
}
LeeGodSRC commented 1 week ago

Can you send the error here if any? if there is no args constructor in the configuration, it shouldn't throw any error.

maurxce commented 1 week ago

Can you send the error here if any?

It's the same error as shown in the issue description (just for the other classes as well), which is why I reopened this.

The behavior is pretty odd, sometimes the configurations work and other times they don't. I wasn't able to find any pattern myself, so I just stopped using configurations wherever possible at this point

LeeGodSRC commented 1 week ago

It sounds quite odd as I hasn't face the issue in any of my project, can you try to replicate a minimal reproducible project and send it here?

maurxce commented 1 week ago

I can try to do that, it just might take a while since it's pretty inconsistent from what I've seen