Skip to content

Commit b808c47

Browse files
committed
JAVA-1221: Avoid possible NPEs in JMXConnectionPoolListener.
1 parent 612b71b commit b808c47

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/main/com/mongodb/JMXConnectionPoolListener.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,49 @@ public void connectionPoolClosed(final ConnectionPoolEvent event) {
7070

7171
@Override
7272
public void connectionCheckedOut(final ConnectionEvent event) {
73-
getStatistics(event).connectionCheckedOut(event);
73+
ConnectionPoolStatistics statistics = getStatistics(event);
74+
if (statistics != null) {
75+
statistics.connectionCheckedOut(event);
76+
}
7477
}
7578

7679
@Override
7780
public void connectionCheckedIn(final ConnectionEvent event) {
78-
getStatistics(event).connectionCheckedIn(event);
81+
ConnectionPoolStatistics statistics = getStatistics(event);
82+
if (statistics != null) {
83+
statistics.connectionCheckedIn(event);
84+
}
7985
}
8086

8187
@Override
8288
public void waitQueueEntered(final ConnectionPoolWaitQueueEvent event) {
83-
getStatistics(event).waitQueueEntered(event);
89+
ConnectionPoolListener statistics = getStatistics(event);
90+
if (statistics != null) {
91+
statistics.waitQueueEntered(event);
92+
}
8493
}
8594

8695
@Override
8796
public void waitQueueExited(final ConnectionPoolWaitQueueEvent event) {
88-
getStatistics(event).waitQueueExited(event);
97+
ConnectionPoolListener statistics = getStatistics(event);
98+
if (statistics != null) {
99+
statistics.waitQueueExited(event);
100+
}
89101
}
90-
91102
@Override
92103
public void connectionAdded(final ConnectionEvent event) {
93-
getStatistics(event).connectionAdded(event);
104+
ConnectionPoolStatistics statistics = getStatistics(event);
105+
if (statistics != null) {
106+
statistics.connectionAdded(event);
107+
}
94108
}
95109

96110
@Override
97111
public void connectionRemoved(final ConnectionEvent event) {
98-
getStatistics(event).connectionRemoved(event);
112+
ConnectionPoolStatistics statistics = getStatistics(event);
113+
if (statistics != null) {
114+
statistics.connectionRemoved(event);
115+
}
99116
}
100117

101118
private ConnectionPoolStatistics getStatistics(final ConnectionEvent event) {

0 commit comments

Comments
 (0)