Skip to content

Conversation

leizhiyuan
Copy link
Contributor

使用了错误的类型判断,所以导致 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 的多个字段,会有访问性问题。
Clipboard_Screenshot_1752739474

@CLAassistant
Copy link

CLAassistant commented Jul 17, 2025

CLA assistant check
All committers have signed the CLA.

Copilot

This comment was marked as outdated.

@hengyunabc
Copy link
Collaborator

可以补充一个测试不?指定在高版本jdk才运行。

@hengyunabc hengyunabc requested a review from Copilot July 17, 2025 15:52
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@@ -587,7 +587,7 @@ else if (Date.class.isInstance(obj)) {
appendStringBuilder(buf, format("@%s[%s]", className, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS").format(obj)));
}

else if (object instanceof Enum<?>) {
else if (obj instanceof Enum<?>) {
Copy link
Preview

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

@hengyunabc hengyunabc merged commit 0aeffc9 into alibaba:master Jul 27, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants