Bug in RoomListenerMultiplexor.java

This code is broken:

public static RoomListenerMultiplexor getRoomMultiplexor(XMPPConnection conn) {

62 synchronized (monitors) {

63 if (!monitors.containsKey(conn)) {

64 RoomListenerMultiplexor rm = new RoomListenerMultiplexor(conn, new RoomMultiplexFilter(),

65 new RoomMultiplexListener());

66

67 rm.init();

68

69 // We need to use a WeakReference because the monitor references the

70 // connection and this could prevent the GC from collecting the monitor

71 // when no other object references the monitor

72 monitors.put(conn, new WeakReference<RoomListenerMultiplexor>(rm));

73 }

74 // Return the InvitationsMonitor that monitors the connection

75 return monitors.get(conn).get();

76 }

77 }

78

Because you can get a NullPointerException in the case when the WeakReference has been GC’ed, since this method will return null. The fix is easy, the if statement should go from being “if (!monitors.containsKey(conn)) {” to “if (!monitors.containsKey(conn) || monitors.get(conn).get() == null) {”

Specifically, if a connection is disconnected and MultiUserChat objects for the rooms the user was in are GC’ed, the weak reference will go null. If the connection is then re-established (for example, through the ReconnectManager) subsequent attempts to join rooms will get NullPointerExceptions since the multiplexor for that connection will have been GC’ed.

I just ran into this same issue. I looked in jira to see if it was accepted as a bug and it has not. Any reason this could not be opened as an issue in jira and be resolved in a future release?

Hi,

I filed it as SMACK-273 , thanks

daryl

Message was edited by: Daryl Herzmann to fix stupid mistake

By filing the bug in OpenFire will it also be resolved in smack?

Doh! Sorry about that.