提交 670c7e8d 编写于 作者: R robm

8205330: InitialDirContext ctor sometimes throws NPE if the server has sent a disconnection

Reviewed-by: chegar, dfuchs
上级 1841f998
/* /*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -115,8 +115,8 @@ public final class LdapClient implements PooledConnection { ...@@ -115,8 +115,8 @@ public final class LdapClient implements PooledConnection {
boolean isLdapv3; // Used by LdapCtx boolean isLdapv3; // Used by LdapCtx
int referenceCount = 1; // Used by LdapCtx for check for sharing int referenceCount = 1; // Used by LdapCtx for check for sharing
Connection conn; // Connection to server; has reader thread final Connection conn; // Connection to server; has reader thread
// used by LdapCtx for StartTLS // used by LdapCtx for StartTLS
final private PoolCallback pcb; final private PoolCallback pcb;
final private boolean pooled; final private boolean pooled;
...@@ -433,19 +433,17 @@ public final class LdapClient implements PooledConnection { ...@@ -433,19 +433,17 @@ public final class LdapClient implements PooledConnection {
(new Throwable()).printStackTrace(); (new Throwable()).printStackTrace();
} }
if (referenceCount <= 0 && conn != null) { if (referenceCount <= 0) {
if (debug > 0) System.err.println("LdapClient: closed connection " + this); if (debug > 0) System.err.println("LdapClient: closed connection " + this);
if (!pooled) { if (!pooled) {
// Not being pooled; continue with closing // Not being pooled; continue with closing
conn.cleanup(reqCtls, false); conn.cleanup(reqCtls, false);
conn = null;
} else { } else {
// Pooled // Pooled
// Is this a real close or a request to return conn to pool // Is this a real close or a request to return conn to pool
if (hardClose) { if (hardClose) {
conn.cleanup(reqCtls, false); conn.cleanup(reqCtls, false);
conn = null;
pcb.removePooledConnection(this); pcb.removePooledConnection(this);
} else { } else {
pcb.releasePooledConnection(this); pcb.releasePooledConnection(this);
...@@ -462,15 +460,11 @@ public final class LdapClient implements PooledConnection { ...@@ -462,15 +460,11 @@ public final class LdapClient implements PooledConnection {
System.err.println("LdapClient: forceClose() of " + this); System.err.println("LdapClient: forceClose() of " + this);
} }
if (conn != null) { if (debug > 0) System.err.println(
if (debug > 0) System.err.println( "LdapClient: forced close of connection " + this);
"LdapClient: forced close of connection " + this); conn.cleanup(null, false);
conn.cleanup(null, false); if (cleanPool) {
conn = null; pcb.removePooledConnection(this);
if (cleanPool) {
pcb.removePooledConnection(this);
}
} }
} }
...@@ -567,7 +561,7 @@ public final class LdapClient implements PooledConnection { ...@@ -567,7 +561,7 @@ public final class LdapClient implements PooledConnection {
* Abandon the search operation and remove it from the message queue. * Abandon the search operation and remove it from the message queue.
*/ */
void clearSearchReply(LdapResult res, Control[] ctls) { void clearSearchReply(LdapResult res, Control[] ctls) {
if (res != null && conn != null) { if (res != null) {
// Only send an LDAP abandon operation when clearing the search // Only send an LDAP abandon operation when clearing the search
// reply from a one-level or subtree search. // reply from a one-level or subtree search.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册