Hi Mariano,

First of all, did you leave out synchronization for simplicity in this
mail or is it not in place at all ?
(assuming you do access EntityManager from multiple threads).

Also, pls doublecheck that EntryManager.java:1529 is really at the
spot you indicated (cannot verify with complete sources).
Specifically i am unsure about databaseHelper. Its just accessed in
you example, so could be null.

At best give the full file so we can check.

Toni

On Tue, Jun 22, 2010 at 11:59 AM, Mariano Kamp <[email protected]> wrote:
> Hey guys.
> This is not an Android issue per-se, but I am puzzled about a Java issue and
> want to pick your brains.
> I recently got a couple of bug reports with a NPE that I don't understand
> and can't reproduce myself. Here is an abbreviated representation of the
> offending class. I tried to stay as close to the actual code as possible.
> public class EntryManager {
>   private static EntryManager instance;
>   private Map<DBQuery, Boolean> isMarkAllReadPossibleCache;
>   private EntryManager(Context ctx) {
>     ..
>     isMarkAllReadPossibleCache = new HashMap<DBQuery, Boolean>();
>     ..
>   }
>   public static synchronized EntryManager getInstance(final Context context)
> {
>        if (instance == null)
>            instance = new EntryManager(context.getApplicationContext());
>        return instance;
>    }
>    void fireModelUpdated(final String atomId) {
>         ..
>         isMarkAllReadPossibleCache.clear();
>         ..
>    }
>   public boolean isMarkAllReadPossible(final DBQuery dbq) {
>         if (!isMarkAllReadPossibleCache.containsKey(dbq))
>             isMarkAllReadPossibleCache.put(dbq,
> databaseHelper.isMarkAllReadPossible(dbq));
>        return isMarkAllReadPossibleCache.get(dbq); <!-- NPE is raised here
>     }
>    ..
> }
> In the last line from above a NPE is thrown. So the instance variable
> isMarkAllReadPossibleCache must be null, right? But I don't see where this
> could happen. It's initialized in the constructor and never set to null
> afterwards.
> For completeness here is a stack trace:
>
> java.lang.NullPointerException
> at com.newsrob.EntryManager.isMarkAllReadPossible(EntryManager.java:1529)
> at
> com.newsrob.activities.AbstractNewsRobListActivity.shouldMarkAllReadButtonBeEnabled(AbstractNewsRobListActivity.java:327)
> at
> com.newsrob.activities.AbstractNewsRobListActivity.updateButtons(AbstractNewsRobListActivity.java:236)
> at
> com.newsrob.activities.AbstractNewsRobListActivity.access$2(AbstractNewsRobListActivity.java:215)
> <-- removed the private access modifier meanwhile
> at
> com.newsrob.activities.AbstractNewsRobListActivity$13.run(AbstractNewsRobListActivity.java:626)
> at android.os.Handler.handleCallback(Handler.java:587)
> at android.os.Handler.dispatchMessage(Handler.java:92)
> at android.os.Looper.loop(Looper.java:123)
> at android.app.ActivityThread.main(ActivityThread.java:4203)
> at java.lang.reflect.Method.invokeNative(Native Method)
> at java.lang.reflect.Method.invoke(Method.java:521)
> at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
> at dalvik.system.NativeStart.main(Native Method)
> Any ideas?
> Cheers,
> Mariano
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en



-- 
Toni Menzel
Independent Software Developer
Professional Profile: http://okidokiteam.com
[email protected]
http://www.ops4j.org     - New Energy for OSS Communities - Open
Participation Software.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to