RemoteCallbackList.getBroadcastItem(int) sometimes returns null

by Streets Of Boston » Fri, 13 Mar 2009 09:08:11 GMT


Sponsored Links
 Hi,

I found out that RemoteCallbackList.getBroadcastItem(int) sometimes
returns null.  I have this code in my Service and it raises a null-
pointer exception:

...
    // instance variable of my Service
    final RemoteCallbackList<IProgressCallback> mCallbacks
            = new RemoteCallbackList<IProgressCallback>();


...
...
public boolean sendProgressCallback(String imgUri, int albumId, int
progressBytes, int progressPercent) {
        final QueuedImageUpload qiu = getUploadingImage(imgUri, albumId);
        if (qiu == null)
            return true;

        qiu.setSizeUploaded(progressBytes);

        final int totalSizePercent = mQueues.calculateRemainingSizePercent();
        final int N = mCallbacks.beginBroadcast();
        try {
                for (int i = 0; i < N; i++) {
                        try {
                                if 
(!mCallbacks.getBroadcastItem(i).progressChanged(qiu.getID(),
imgUri, albumId, progressPercent, totalSizePercent)) {
                                        return false;
                                }
                        } catch (RemoteException e) {
                                // The RemoteCallbackList will take care of 
removing
                                // the dead object for us.
                        }
                }
        }
        finally {
                mCallbacks.finishBroadcast();
        }
        return true;
}

This line is the one throwing a nullpointer exception:
"if (!mCallbacks.getBroadcastItem(i).progressChanged(qiu.getID(),
imgUri, albumId, progressPercent, totalSizePercent))"

- The mCallbacks is never null. It is declared as final.
- The local 'qui' stack-variable is never null. It is guarded by a
null-pointer check.

That only leads me to conclude that the call getBroadcastItem(i)
returns null. However, the documentation states that this method never
returns null. Is this a bug in Android?

This problem only happens on occasion (I can not reproduce it
consistently), but it happens often enough to be of concern for my
app.

BTW, someone else reported the same problem a while ago:




RemoteCallbackList.getBroadcastItem(int) sometimes returns null

by Streets Of Boston » Fri, 13 Mar 2009 11:08:48 GMT


 mmmmmmmm.... you mean that the value of 'N 'could be larger than the
actual elements accessed by getBroadcastItem(i), i.e. HashMap changes
while looping over the 'N' items...?

For now, i'm check for null and just ignore it. The problem is that it
is very hard to reproduce. It happens on rare occasions, but often
enough to be problematic.

This line has only 3 points in which it could throw a null-pointer
exception (the stack-trace reports the NPE on this line, not inside
progressChanged(...)):
- mCallbacks is null: Not possible. It is declared final and refers to
an instance.
- qiu is null: Not possible. It is a stack-variable and it has been
guarded against null value.
- getBroadcastItem(i): The only one left...

I thought that beginBroadcast() would lock the callback-list for
modification and finishBroadcast() would unlock it again. This way, N
should always be the number of items in this HashMap you were
mentioning. Am i correct in this.

I'll let you know if i can figure out which values for 'i' are
problematic :-)

Thanks for your help.

On Mar 12, 9:27pm, Dianne Hackborn <hack...@android.com> wrote:
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


RemoteCallbackList.getBroadcastItem(int) sometimes returns null

by Streets Of Boston » Fri, 13 Mar 2009 22:27:37 GMT


 Ah, thanks.

Either way, it means that the number of items in the list accessed by
getBroadcastItem is always equal to N.
The problem remains: How can getBroadcastItem(int) return null?




--~--~---------~--~----~------------~-------~--~----~



RemoteCallbackList.getBroadcastItem(int) sometimes returns null

by Streets Of Boston » Sat, 14 Mar 2009 01:56:08 GMT


 Ah, now i get it! :-)

Indeed, sendProgressCallback can be called from multiple threads. And
with your earlier explanation that the beginBroadcast does not do
locking (only a brief internal lock), it may explain the problem. In
other words, RemoteCallbackList is not thread-safe across multiple
calls to it.

I should put the broadcast code inside a 'synchronized(mCallbacks)
{ ... }' block or surround it with a ReentrantLock.
Or create mCallbacks instances for each possible thread and have my
listeners register with each of them.

Thank you very much for your help.
Have a great weekend!




--~--~---------~--~----~------------~-------~--~----~



RemoteCallbackList.getBroadcastItem(int) sometimes returns null

by Streets Of Boston » Sat, 14 Mar 2009 03:50:14 GMT


 las, this one is not a one-way interface. It expects a boolean back:
False = cancel upload of image, True = continue uploading image. It
allows the (remote) client to cancel uploads forcefully. Luckily, the
client receiving the call-back can return this answer really fast.

The client is not the same process. It is a different app (Activity)
in a different process.

What is your opinion, in terms of speed/performance: One 'mCallbacks'
instance for the Service, sending this callback to its clients, inside
a synchronized(...) block or having each a 'mCallbacks' for each
thread (max 3)? Which one would be better?
The client is always remote (other process).

Thanks!
On Mar 13, 2:29pm, Dianne Hackborn <hack...@android.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. YAFFS2 filesystem in Android linux?

Hi all,
I am a newbie to Android kernel development.  The robustness of the file
system is very critical for a mobile
device.  YAFFS2 is a file system that was designed specifically for NAND
flash, which is supposed to be more robust than EXT3 file system in terms of
NAND flash.  I wonder if there is YAFF2 support in Android platform? or
there is an alternative other than EXT3?

Any hint is very appreciated.

Best
Hugo

--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-kernel+unsubscr...@googlegroups.com
website: 

2. conatct/calender/dialer does not launch

hello,

I have android 1.5 running on developer board which does not have
touhchscreen and all keboard keys are passed through UART. All
application works except contact, calender and dialer. When these
applciations are launched "android.process.acore has stopped
unexpectdegly" error comes wth force close.

Below is the log and It s not clear resourcetype get is failing and
ultimatly VM is shutting down.   Any idea?



# D/dalvikvm(  887): GC freed 315 objects / 14056 bytes in 113ms
^[[CW/KeyCharacterMap(  887): No keyboard for id 0
W/KeyCharacterMap(  887): Using default keymap: /system/usr/keychars/
qwerty.kcm.
bin
^[[A
: not found
# I/ActivityManager(  518): Starting activity: Intent
{ action=android.intent.ac
tion.MAIN categories={android.intent.category.LAUNCHER}
flags=0x10200000 comp={c
om.android.contacts/
com.android.contacts.DialtactsContactsEntryActivity} }
W/InputManagerService(  518): Starting input on non-focused client
com.android.i
nternal.view.iinputmethodclient$stub$pr...@4376d8c8 (uid=10004
pid=887)
W/ResourceType(  887): Failure getting entry for 0x7f030005 (t=2 e=5)
in package
 0: 0xffffffb5
D/AndroidRuntime(  887): Shutting down VM
W/dalvikvm(  887): threadid=3: thread exiting with uncaught exception
(group=0x4
000fe70)
E/AndroidRuntime(  887): Uncaught handler: thread main exiting due to
uncaught e
xception
E/AndroidRuntime(  887): java.lang.RuntimeException: Unable to start
activity Co
mponentInfo{com.android.contacts/
com.android.contacts.DialtactsActivity}: androi
d.content.res.Resources$NotFoundException: Resource ID #0x7f030005
E/AndroidRuntime(  887):        at
android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2268)
E/AndroidRuntime(  887):        at
android.app.ActivityThread.handleLaunchActivi
ty(ActivityThread.java:2284)
E/AndroidRuntime(  887):        at android.app.ActivityThread.access$1800
(Activi
tyThread.java:112)
E/AndroidRuntime(  887):        at android.app.ActivityThread$H.handleMessage
(Ac
tivityThread.java:1692)
E/AndroidRuntime(  887):        at android.os.Handler.dispatchMessage
(Handler.ja
va:99)
E/AndroidRuntime(  887):        at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  887):        at android.app.ActivityThread.main
(ActivityThrea
d.java:3948)
E/AndroidRuntime(  887):        at java.lang.reflect.Method.invokeNative
(Native
Method)
E/AndroidRuntime(  887):        at java.lang.reflect.Method.invoke
(Method.java:5
21)
E/AndroidRuntime(  887):        at com.android.internal.os.ZygoteInit
$MethodAndA
rgsCaller.run(ZygoteInit.java:782)
E/AndroidRuntime(  887):        at com.android.internal.os.ZygoteInit.main
(Zygot
eInit.java:540)
E/AndroidRuntime(  887):        at dalvik.system.NativeStart.main(Native
Method)
E/AndroidRuntime(  887): Caused by: android.content.res.Resources
$NotFoundExcept
ion: Resource ID #0x7f030005
E/AndroidRuntime(  887):        at android.content.res.Resources.getValue
(Resour
ces.java:846)
E/AndroidRuntime(  887):        at
android.content.res.Resources.loadXmlResource
Parser(Resources.java:1796)
E/AndroidRuntime(  887):        at android.content.res.Resources.getLayout
(Resou
rces.java:685)
E/AndroidRuntime(  887):        at android.view.LayoutInflater.inflate
(LayoutInf
later.java:318)
E/AndroidRuntime(  887):        at android.view.LayoutInflater.inflate
(LayoutInf
later.java:276)
E/AndroidRuntime(  887):        at
com.android.internal.policy.impl.PhoneWindow.
setContentView(PhoneWindow.java:309)
E/AndroidRuntime(  887):        at android.app.Activity.setContentView
(Activity.
java:1626)
E/AndroidRuntime(  887):        at
com.android.contacts.DialtactsActivity.onCrea
te(DialtactsActivity.java:73)
E/AndroidRuntime(  887):        at
android.app.Instrumentation.callActivityOnCre
ate(Instrumentation.java:1123)
E/AndroidRuntime(  887):        at
android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:2231)
E/AndroidRuntime(  887):        ... 11 more
I/Process (  518): Sending signal. PID: 887 SIG: 3
I/dalvikvm(  887): threadid=7: reacting to signal 3
I/dalvikvm(  887): Wrote stack trace to '/data/anr/traces.txt'
D/dalvikvm(  518): GC freed 9343 objects / 436720 bytes in 172ms
E/ActivityThread(  518): Failed to find provider info for
android.server.checkin
E/Checkin (  518): Error reporting crash:
java.lang.IllegalArgumentException: Un
known URL content://android.server.checkin/crashes
W/ActivityManager(  518): Launch timeout has expired, giving up wake
lock!
W/ActivityManager(  518): Activity idle timeout for HistoryRecord
{43767d18 {com.
android.contacts/com.android.contacts.DialtactsContactsEntryActivity}}


--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. how to create a custom listener for some objects..

4. booting up the emulator with custom kernel build

5. cannot find htonl

6. Help with WiFinder

7. Is it possible to change text color of all child TextViews