From edeb87c7f45a7e0367b7375045441fdf75a8983e Mon Sep 17 00:00:00 2001 From: Looly Date: Tue, 28 Oct 2025 18:23:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D`HttpConnection.reflectSetMet?= =?UTF-8?q?hod`=E5=8F=8D=E5=B0=84=E5=9C=A8JDK9+=E6=9D=83=E9=99=90=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=88issue#4109@Github=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 ++- .../java/cn/hutool/http/HttpConnection.java | 17 +++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6447a0162..a6de785a6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # 🚀Changelog ------------------------------------------------------------------------------------------------------------- -# 5.8.42(2025-10-24) +# 5.8.42(2025-10-28) ### 🐣新特性 * 【core 】 `ListUtil`增加`zip`方法(pr#4052@Github) @@ -14,6 +14,7 @@ * 【extra 】 修复`JschSessionPool.remove`逻辑错误问题。 * 【db 】 修复`Dialect.psForCount`未传入Wrapper导致大小写问题(issue#ID39G9@Gitee)。 * 【core 】 修复`PasswdStrength.check`indexOf逻辑问题(pr#4114@Github)。 +* 【htp 】 修复`HttpConnection.reflectSetMethod`反射在JDK9+权限问题(issue#4109@Github)。 ------------------------------------------------------------------------------------------------------------- # 5.8.41(2025-10-12) diff --git a/hutool-http/src/main/java/cn/hutool/http/HttpConnection.java b/hutool-http/src/main/java/cn/hutool/http/HttpConnection.java index 1e712691f..91386f94c 100644 --- a/hutool-http/src/main/java/cn/hutool/http/HttpConnection.java +++ b/hutool-http/src/main/java/cn/hutool/http/HttpConnection.java @@ -598,16 +598,21 @@ public class HttpConnection { } /** - * 通过反射设置方法名,首先设置HttpURLConnection本身的方法名,再检查是否为代理类,如果是,设置带路对象的方法名。 + * 通过反射设置方法名,首先设置HttpURLConnection本身的方法名,再检查是否为代理类,如果是,设置代理对象的方法名。 * @param method 方法名 */ private void reflectSetMethod(Method method){ - ReflectUtil.setFieldValue(this.conn, "method", method.name()); + try { + ReflectUtil.setFieldValue(this.conn, "method", method.name()); - // HttpsURLConnectionImpl实现中,使用了代理类,需要修改被代理类的method方法 - final Object delegate = ReflectUtil.getFieldValue(this.conn, "delegate"); - if(null != delegate){ - ReflectUtil.setFieldValue(delegate, "method", method.name()); + // HttpsURLConnectionImpl实现中,使用了代理类,需要修改被代理类的method方法 + final Object delegate = ReflectUtil.getFieldValue(this.conn, "delegate"); + if(null != delegate){ + ReflectUtil.setFieldValue(delegate, "method", method.name()); + } + } catch (Exception e){ + // ignore + // https://github.com/chinabugotech/hutool/issues/4109 } } // --------------------------------------------------------------- Private Method end