You are right, I simplified the class for the mailing list. But in the real 
class, I have a private default constructor. I'm not at work anymore but I will 
check as soon as possible tomorrow morning.Andreas Prieß <[email protected]> 
a écrit :Hi,

the version of EventBuilder you posted is not really a singleton, it has
a public default constructor. So to me it seems you will end up with two
instances of EventBuilder:

One created by iPOJO and injected with an EventDispatcher and the one
that will be created implicitly by the line:

private static final EventBuilder INSTANCE = new EventBuilder();

So when you use the field INSTANCE in your code, that is _not_ the
instance that was injected with EventDispatcher. Therefore you still get
a NPException.


HTH,

Andreas


On 10.10.2011 14:57, Benoît Thiébault wrote:
> I replaced the line:
> private EventDispatcher dispatcher = null;
> by:
> private EventDispatcher dispatcher;
> 
> I still have a null pointer exception. Is it possible that this
> behaviour due to the fact that the class construction is done when I
> first call one of its static methods (in particular the declaration
> private static final EventBuilder INSTANCE = new EventBuilder();) ?

>>>> The implementation looks like this (this is a simplified version of it):
>>>>
>>>> public final class EventBuilder {
>>>>   /** Unique instance of the builder */
>>>>   private static final EventBuilder INSTANCE = new EventBuilder();
>>>>   /** Event to trigger. */
>>>>   private static Event eventToTrigger;
>>>>   /** Reference to the dispatcher to use. */
>>>>   private EventDispatcher dispatcher = null;
>>>>   /** Lock to prevent concurrent modifications. */
>>>>   private static final Lock LOCK = new ReentrantLock();
>>>>
>>>> public static EventBuilder event(final EventKey key) {
>>>>       LOCK.lock();
>>>>       eventToTrigger = new DefaultEvent(key);
>>>>       return INSTANCE;
>>>> }
>>>>
>>>> public void triggerCallEvent() {
>>>>       try {
>>>>           dispatcher.triggerCallEvent(eventToTrigger);
>>>>       } finally {
>>>>           LOCK.unlock();
>>>>       }
>>>> }
>>>> }

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to