paulkavule / seek-for-android

Automatically exported from code.google.com/p/seek-for-android
0 stars 0 forks source link

new SEService() throw NullPointerException when listener is null #20

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
According to 
http://seek-for-android.googlecode.com/svn/trunk/doc/org/simalliance/openmobilea
pi/SEService.html#SEService(Context, 
org.simalliance.openmobileapi.SEService.CallBack)

public SEService(Context context,
                 SEService.CallBack listener)

listener - a SEService.CallBack object. Can be null.

However, when calling the function like this:

try
{
    seService = new SEService(m_activity, null);
} catch (Exception e)
{
}

while (!seService.isConnected())
{           
    try
    {
        Thread.sleep(100);
    } catch (Exception e)
    {
    }
}

java.lang.NullPointerException: listener must not be null is thrown.

expected behavior is that exception is not thrown and the following while loop 
should be terminated when after the SEService is connected. (normally when a 
callback occur).

Original issue reported on code.google.com by tommypo...@gmail.com on 2 May 2012 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by Daniel.A...@gi-de.com on 8 May 2012 at 2:09

GoogleCodeExporter commented 9 years ago
because the logic on calling back is already implemented in the safe way that 
it would not do anything if mCallerCallback == null
while there is no other place that is using mCallerCallback.  Only other thing 
that need is to make a comment on declaration like this.

private CallBack mCallerCallback;  // can be null

propose solution as following:

public SEService(Context context, SEService.CallBack listener) {

        if (context == null) {
            throw new NullPointerException("context must not be null");
        }
        // propose solution start, comment out the following
        //if (listener == null) {
        //    throw new NullPointerException("listener must not be null");
        //}
        // propose solution end

        mContext = context;
        mCallerCallback = listener;

        mConnection = new ServiceConnection() {

            public synchronized void onServiceConnected(ComponentName className, IBinder service) {

                mSmartcardService = ISmartcardService.Stub.asInterface(service);
                if (mCallerCallback != null) {
                    mCallerCallback.serviceConnected(SEService.this);
                }
                Log.v(SERVICE_TAG, "Service onServiceConnected");
            }

            public void onServiceDisconnected(ComponentName className) {

                synchronized (mReaders) {

                    for (Reader reader : mReaders) {
                        try {
                            reader.closeSessions();
                        } catch (Exception ignore) {
                        }
                    }
                }
                mSmartcardService = null;
                Log.v(SERVICE_TAG, "Service onServiceDisconnected");
            }
        };

        boolean bindingSuccessful = mContext.bindService(new Intent(ISmartcardService.class
                .getName()), mConnection, Context.BIND_AUTO_CREATE);
        if (bindingSuccessful) {
            Log.v(SERVICE_TAG, "bindService successful");
        }
    }

Original comment by tommypo...@gmail.com on 11 May 2012 at 2:58

GoogleCodeExporter commented 9 years ago
Accepted solution according to Comment 2.

Original comment by schus...@gmail.com on 18 May 2012 at 6:11

Attachments:

GoogleCodeExporter commented 9 years ago
setting old issues from fixed to done

Original comment by Daniel.A...@gi-de.com on 5 Jul 2013 at 2:33