Conversation
|
可以补充一个测试不?指定在高版本jdk才运行。 |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in the ObjectView class where enum objects were not being handled correctly due to an incorrect variable reference in the type check. The fix ensures that enum objects are properly formatted in the ObjectView output, particularly addressing accessibility issues that occur in higher JDK versions.
- Fixed incorrect variable reference in enum type checking logic
- Added comprehensive test coverage for enum handling in ObjectView
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| ObjectView.java | Fixed variable reference from object to obj in enum instanceof check |
| ObjectViewTest.java | Added test cases for single enum and enum array formatting |
| } | ||
|
|
||
| else if (object instanceof Enum<?>) { | ||
| else if (obj instanceof Enum<?>) { |
There was a problem hiding this comment.
This fix correctly changes the variable reference from 'object' to 'obj' to match the actual variable being checked. The previous code was using an undefined 'object' variable instead of the 'obj' parameter, which would have caused the enum condition to never be true.
使用了错误的类型判断,所以导致 enum 枚举走了不该走的逻辑。
在 jdk 高版本 的场景下,会有问题。
ts=2025-07-17 15:58:47.327; [cost=0.03725ms] result=ERROR DATA!!! object class: class java.util.ArrayList, exception class: class java.lang.reflect.InaccessibleObjectException, exception message: Unable to make field private final java.lang.String java.lang.Enum.name accessible: module java.base does not "opens java.lang" to unnamed module @3d3762e1
这里会遍历 enum 的多个字段,会有访问性问题。
