Bug in RoomListenerMultiplexor.java

Description

http://www.igniterealtime.org/community/message/192927

This code is broken:

public static RoomListenerMultiplexor getRoomMultiplexor(XMPPConnection conn) {

62 synchronized (monitors) {

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

64 &nbsp ; RoomListenerMultiplexor rm = new RoomListenerMultiplexor(conn, new RoomMultiplexFilter(),

65 &nbsp ; new RoomMultiplexListener());

66

67 &nbsp ; rm.init();

68

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

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

71 &nbsp ; // when no other object references the monitor

72 &nbsp ; 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) {"

Environment

None

Activity

Show:
Wolf P.
June 1, 2011, 7:41 AM

Completed: At revision: 12441 in 3.2.0branch

Fixed

Assignee

Wolf P.

Reporter

Daryl Herzmann