Merge pull request #4143 from CherryRum/v5-dev

修改部分描述
This commit is contained in:
Golden Looly 2025-11-23 23:11:00 +08:00 committed by GitHub
commit 9dad6fc4d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 7 deletions

View File

@ -4,15 +4,35 @@ import java.io.Serializable;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 本地端口生成器<br>
* 用于生成本地可用未被占用的端口号<br>
* 注意多线程甚至单线程访问时可能会返回同一端口例如获取了端口但是没有使用
* 本地端口生成器LocalPortGenerator
* <p>
* 当前类名中Generater为拼写错误正确应为 Generator为保持兼容性暂未更改
* 该问题将在后续大版本中以重命名方式修复并保留旧类名的弃用@Deprecated兼容层
* <p>
*
* 用于从指定起点开始递增探测一个当前可用的本地端口探测通过短暂绑定
* {@link java.net.ServerSocket}以及可选 UDP DatagramSocket完成但不会真正占用端口
* <p>注意</p>
* <ul>
* <li>该方法执行的是端口探测分配返回端口不保证实际使用时仍然可用</li>
* <li>存在 TOCTOU检测到使用之间竞态多线程下可能返回同一端口</li>
* <li>UDP 探测可能导致误判TCP 可用但 UDP 被占用</li>
* <li>不适合作为生产级端口分配策略推荐使用 {@code new ServerSocket(0)}</li>
* </ul>
*
* <p>未来版本计划</p>
* <ul>
* <li>修复类名拼写问题Generater更名为 Generator</li>
* <li>提供真正可靠的端口获取实现绑定即占用避免竞态</li>
* <li>优化探测策略减少不必要的 UDP 检测</li>
* <li>提供更安全的随机端口生成 API</li>
* </ul>
* @author looly
* @since 4.0.3
*
*/
public class LocalPortGenerater implements Serializable{
public class LocalPortGenerater implements Serializable{
private static final long serialVersionUID = 1L;
/** 备选的本地端口 */

View File

@ -270,7 +270,7 @@ public class URLUtil extends URLEncodeUtil {
try {
return file.toURI().toURL();
} catch (MalformedURLException e) {
throw new UtilException(e, "Error occured when get URL!");
throw new UtilException(e, "Error occurred when get URL!");
}
}
@ -288,7 +288,7 @@ public class URLUtil extends URLEncodeUtil {
urls[i] = files[i].toURI().toURL();
}
} catch (MalformedURLException e) {
throw new UtilException(e, "Error occured when get URL!");
throw new UtilException(e, "Error occurred when get URL!");
}
return urls;