dromara / hutool

🍬A set of tools that keep Java sweet.
https://hutool.cn
Other
29.25k stars 7.54k forks source link

ReUtiil.getAllGroupNames 不支持jdk17 #3764

Closed lijiajia3515 closed 1 month ago

lijiajia3515 commented 1 month ago

版本情况

JDK版本: corretto-17.0.12 hutool版本: 5.8.32(请确保最新尝试是否还有问题)

问题描述(包括截图)

  1. 复现代码
        Pattern S3_PATTERN = Pattern.compile("^((?<schema>s3[na]?)://)((?<auth>.*:.*)@)?(?<bucket>[^/\\n]{3,63})/(?<path>[^?:]{1,1024})(\\?version=(?<version>.*)?)?$");
        String test = "s3://public/test/20240627/2.png?version=b8922b5b-a4cd-40ab-a9a7-ec759451dfdb";
        ReUtil.getAllGroupNames(S3_PATTERN,test);
  1. 堆栈信息
    Exception in thread "main" java.lang.reflect.InaccessibleObjectException: Unable to make java.util.Map java.util.regex.Pattern.namedGroups() accessible: module java.base does not "opens java.util.regex" to unnamed module @15db43e4
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
    at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
    at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:200)
    at java.base/java.lang.reflect.Method.setAccessible(Method.java:194)
    at cn.hutool.core.util.ReflectUtil.setAccessible(ReflectUtil.java:1122)
    at cn.hutool.core.util.ReflectUtil.invokeRaw(ReflectUtil.java:1047)
    at cn.hutool.core.util.ReflectUtil.invoke(ReflectUtil.java:1016)
    at cn.hutool.core.util.ReflectUtil.invoke(ReflectUtil.java:1109)
    at cn.hutool.core.util.ReUtil.getAllGroupNames(ReUtil.java:265)
    at com.yiruibim.cairo.auth.modules.account.Test.main(Test.java:11)
  2. 测试涉及到的文件(注意脱密)

比如报错的Excel文件,有问题的图片等。

lijiajia3515 commented 1 month ago

jdk8 中提示警告,但是调用正常

WARNING: Illegal reflective access by cn.hutool.core.util.ReflectUtil (file:/Users/lijiajia/.gradle/caches/modules-2/files-2.1/cn.hutool/hutool-core/5.8.11/d3d5deb146e51eef43383202921c7dd4ecc7ff07/hutool-core-5.8.11.jar) to method java.util.regex.Pattern.namedGroups()

WARNING: Please consider reporting this to the maintainers of cn.hutool.core.util.ReflectUtil

WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations

WARNING: All illegal access operations will be denied in a future release
looly commented 1 month ago

这个方法调用了Pattern中的yi一个私有属性, image

因此使用了反射。JDK9+做了反射限制,导致失败。

考虑其他方法。