2007年12月15日土曜日

[JAVA>JML, MSN Messenger] When using JML(Java MSN Messenger Library), NullPointerException occured

References
  1. Reference Site
    Java MSN Messenger Library (JML) Home: http://java-jml.sourceforge.net/
Problems
In case of using Java MSN Messenger Library(JML), NullPointerException occures when adding a friend into Friend List or removing a friend from Friend List, but this problem doesn't always occured.

Reason why this problem occures
System checks whether a friend is already added into the list or not before adding or removing a friend. When checking a friend, System accesses the user's contact list object and get contact information from the contact list object.
When a friend doesn't contain the user's contact list, system returns the null value. And then, system accesses the object even though the value of the contact object is null.

Solution Example
Change addFriend() and removeFriend() function int the net.sf.jml.impl.SimpleMessenger.java file as follows. You need to check whether the value of MsnContact object is nujll or not.
  1. addFriend function

    private void addFriend(MsnList list, Email email, String friendlyName) {
    if (list == null || email == null || list == MsnList.RL
    || list == MsnList.PL)
    return;
    MsnContact contact = getContactList().getContactByEmail(email);
    /*
    * added by tatsuya anno to avoid NullPointerException
    * because contact object is null when adding new user
    */
    if(contact!=null){
    if (contact.isInList(list)){
    return;
    }
    }
    /*
    * End of Bugfix
    */
    .......
    }


  2. removeFriend function

    private void removeFriend(MsnList list, Email email, String id,
    String groupId) {
    if (list == null || list == MsnList.RL)
    return;
    if (list == MsnList.FL) {
    if (id == null)
    return;
    } else if (email == null)
    return;
    MsnContact contact = getContactList().getContactByEmail(email);

    /*
    * added by tatsuya anno to avoid NullPointerException
    * because contact object is null when adding new user
    */
    if(contact!=null){
    if (!contact.isInList(list)){
    return;
    }
    }
    /*
    * End of Bugfix
    */
    ......
    }

0 件のコメント: