修复JschSessionPool.remove逻辑错误问题。

This commit is contained in:
Looly
2025-10-23 11:16:12 +08:00
parent fb95caa7b9
commit 4c563da8bd
3 changed files with 44 additions and 8 deletions

View File

@@ -4,7 +4,7 @@ import cn.hutool.core.lang.SimpleCache;
import cn.hutool.core.util.StrUtil;
import com.jcraft.jsch.Session;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
/**
@@ -110,15 +110,17 @@ public enum JschSessionPool {
*/
public void remove(Session session) {
if (null != session) {
final Iterator<Entry<String, Session>> iterator = this.cache.iterator();
Entry<String, Session> entry;
while (iterator.hasNext()) {
entry = iterator.next();
String key = null;
for (Map.Entry<String, Session> entry : cache) {
if (session.equals(entry.getValue())) {
iterator.remove();
key = entry.getKey();
break;
}
}
if(null != key){
cache.remove(key);
}
}
}