Hi core-guys!
Tried to warm up again with qi4j. I started to play with the @Service
annotation to inject a simple ojbect as a service.
Tried the following (see below), assuming that a default constructor for
the service and default settings in the runtime should suffice.
I got the exception as shown below.
I found that the objectModelFactory created in Energy4Java, will never
be assigned to this.objectModelFactory, but to the parameter with the
same name. The objectBuilderFactory which is later on created, is
assigned to this.objectBuilderFactory later on, but never read. The
newObjectBuilderFactory() does not use it, but creates a new instance
again, which gets the unassigned objectModelFactory.
Guess this is a bug, or?
Question: Should my code have been run (without this assumed bug)? Or is
my setup to mean, to naive, absolutely wrong, ...?
To be naughty: Wasn't there a discussion about final on parameters and
parameter assignment lately? :)
So long,
Georg
<Main.java>
public class Main {
public static void main(String[] args) {
Qi4j api = new Energy4Java();
CompositeBuilderFactory cbf = api.newCompositeBuilderFactory();
CompositeBuilder<GeekComposite> ccb = cbf
.newCompositeBuilder(GeekComposite.class);
Geek geek = ccb.newInstance();
System.out.println(geek.say());
}
public interface Geek {
String say();
}
@Mixins(GeekSayMixin.class)
interface GeekComposite extends Composite, Geek {
}
public abstract static class GeekSayMixin implements Geek {
@Service
RandomSloganService service;
@Override
public String say() {
return "My personal geek-slogan today: " + service.nextSlogan();
}
}
public static class RandomSloganService {
private Random rand = new Random(System.currentTimeMillis());
private String names[] = {
"There are 10 types of people in the world: "
+ "Those who understand binary, and those who don't...",
"There's no place like 127.0.0.1", "You had me at EHLO." };
public String nextSlogan() {
return names[rand.nextInt(names.length)];
}
}
}
</Main.java>
<Exception>
Exception in thread "main" java.lang.NullPointerException
at
org.qi4j.runtime.ObjectBuilderFactoryImpl.getObjectResolution(ObjectBuilderFactoryImpl.java:68)
at
org.qi4j.runtime.ObjectBuilderFactoryImpl.newObjectBuilder(ObjectBuilderFactoryImpl.java:51)
at
org.qi4j.runtime.resolution.ServiceDependencyResolver.resolveDependency(ServiceDependencyResolver.java:60)
at
org.qi4j.runtime.resolution.DependencyResolverRegistryImpl.resolveDependency(DependencyResolverRegistryImpl.java:36)
at
org.qi4j.runtime.resolution.ObjectModelResolver.resolveFieldDependencies(ObjectModelResolver.java:76)
at
org.qi4j.runtime.resolution.MixinModelResolver.resolveModel(MixinModelResolver.java:26)
at
org.qi4j.runtime.resolution.CompositeModelResolver.getResolvedMixins(CompositeModelResolver.java:123)
at
org.qi4j.runtime.resolution.CompositeModelResolver.resolveCompositeModel(CompositeModelResolver.java:55)
at
org.qi4j.runtime.CompositeBuilderFactoryImpl.getCompositeContext(CompositeBuilderFactoryImpl.java:59)
at
org.qi4j.runtime.CompositeBuilderFactoryImpl.newCompositeBuilder(CompositeBuilderFactoryImpl.java:48)
at samples.Main.main(Main.java:19)
</Exception>
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev