bhq / asmack

Automatically exported from code.google.com/p/asmack
Other
0 stars 0 forks source link

MultiUserChat.addInvitationListener(conn, "") throws nullpointerexception when reconnecting #82

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,
I got a NullPointerException on MultiUserChat.addInvitationListener when 
connecting at 2nd ,I think InvitationsMonitor.getInvitationsMonitor(conn) in 
MultiUserChat.java return null

  public static InvitationsMonitor getInvitationsMonitor(Connection conn) {
            synchronized (monitors) {
                if (!monitors.containsKey(conn)) {
              // We need to use a WeakReference because the monitor references the
             // connection and this could prevent the GC from collecting the monitor
            // when no other object references the monitor
            monitors.put(conn, new WeakReference<InvitationsMonitor>(new InvitationsMonitor(conn)));
                }
                // Return the InvitationsMonitor that monitors the connection
                return monitors.get(conn).get();
            }

It may be fixed by change "if (!monitors.containsKey(conn))" to "if 
(!monitors.containsKey(conn) || monitors.get(conn).get() == null)"

can you give me some direction about it? 
Thanks

Original issue reported on code.google.com by yanchend...@gmail.com on 12 May 2013 at 4:30

GoogleCodeExporter commented 9 years ago
Filled as upstream bug 
[SMACK-438|http://issues.igniterealtime.org/browse/SMACK-438]

Original comment by fschm...@gmail.com on 12 May 2013 at 2:08

GoogleCodeExporter commented 9 years ago
Thank you very much! Concurrent WeakHashMap is a good idea,very 
enlightening.I'll wait fixed version of aSmack.
Thanks!

Original comment by yanchend...@gmail.com on 21 May 2013 at 4:18