typesafeconfig-guice
typesafeconfig-guice copied to clipboard
Exception received when Lambda expressions used inside @Provides method.
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;
}
}
P.S. Awesome library!
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...