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

Exception received when Lambda expressions used inside @Provides method. #6

Open
ryonday opened this issue Jun 23, 2017 · 2 comments
Open

Comments

@ryonday
Copy link

ryonday commented Jun 23, 2017

Let's make a module:

public class TestModule extends AbstractModule {

@Override
    protected void configure() {

        Config config = ConfigFactory.load().getConfig("here.we.go");

        install(TypesafeConfigModule.fromConfigWithPackage(config, "stuff.package"));
    }
}

For some reason, we want to provide a String based on what's in the config (stupid example):

    @Provides
    @Singleton
    private String someString( @TypesafeConfig("one") String one,
                                   @TypesafeConfig("two") String two,
                                   @TypesafeConfig("three") String three) {

        return Optional.ofNullable(one)
            .map( s -> two)
            .orElse(three);
    }

This will result in the following exception:

Jun 23, 2017 1:48:01 PM com.google.inject.internal.MessageProcessor visit
INFO: An exception was caught and reported. Message: org.reflections.ReflectionsException: Can't resolve member named 0 for class package.for.TestModule.lambda$someString
org.reflections.ReflectionsException: Can't resolve member named 0 for class package.for.TestModule..lambda$someString

Apparently the Reflections package counts the lambdas in the method as separate classes (which they are).

This, however works:

    @Provides
    @Singleton
    private String someString( @TypesafeConfig("one") String one,
                                   @TypesafeConfig("two") String two,
                                   @TypesafeConfig("three") String three) {

         if(one == null) {
            return two;
        } else {
            return three;
        }
    }
@ryonday
Copy link
Author

ryonday commented Jun 23, 2017

P.S. Awesome library!

@racc
Copy link
Owner

racc commented Jun 26, 2017

Thanks @ryonday. Seems like a weird bug, but at least you have a workaround :)
Happy to take a patch if you have one, but it might be a little while before I can take a look at it otherwise...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants