Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed hashCode cause StackOverflowError issue for scala3 project #99

Open
wants to merge 1 commit into
base: feature-1.x
Choose a base branch
from

Conversation

fkong-bgl
Copy link

No description provided.

@fkong-bgl fkong-bgl changed the title Fixed hashCode StackOverflowError issue for scala3 project Fixed hashCode cause StackOverflowError issue for scala3 project Nov 27, 2024
@psxjoy
Copy link
Collaborator

psxjoy commented Nov 27, 2024

I think we should add unit test cases to validate . And also verify if this is a widespread issue.

我认为我们应该增加一些单元测试用例作为校验。同时要确认这是否是个普遍的问题。

@fkong-bgl
Copy link
Author

fkong-bgl commented Nov 27, 2024

I think we should add unit test cases to validate . And also verify if this is a widespread issue.

我认为我们应该增加一些单元测试用例作为校验。同时要确认这是否是个普遍的问题。

这是一个普遍问题,@EqualsAndHashCode 生成hashCode和toString时,对象循环引用了.
只要代码里显式调用hashCode,toString方法,必须报 java.lang.StackOverflowError 异常

重现测试代码如下:

public class HashCodeStackOverflowErrorTest {
    @Test
    public void writeTest() {
        String fileName = TestFileUtil.getPath() + "indexWrite" + System.currentTimeMillis() + ".csv";
        System.out.println(fileName);
     
        EasyExcel.write(fileName, IndexData.class).excelType(ExcelTypeEnum.CSV).sheet("模板")
        .registerWriteHandler(new CustomCsvWriteListener())
        .doWrite(data());
    }

    private List<DemoData> data() {
        List<DemoData> list = ListUtils.newArrayList();
        for (int i = 0; i < 10; i++) {
            DemoData data = new DemoData();
            data.setString("字符串" + i);
            data.setDate(new Date());
            data.setDoubleData(0.56);
            list.add(data);
        }
        return list;
    }

}

  class CustomCsvWriteListener implements RowWriteHandler {


    public void afterRowDispose(RowWriteHandlerContext context) {
        if (BooleanUtils.isTrue(context.getHead())) {
        	 WriteSheetHolder sheetHolder=context.getWriteSheetHolder();
        	 sheetHolder.hashCode(); //@EqualsAndHashCode 没排除循环引用对象,引起java.lang.StackOverflowError 
        	//  sheetHolder.toString();
             
        }
    }
}

@fkong-bgl
Copy link
Author

@psxjoy @CaoZhengxi @Chat2DB-Pro
Please have look this PR,thank you

@psxjoy
Copy link
Collaborator

psxjoy commented Dec 18, 2024

We’re still assessing the impact. Please verify the following:

  1. All conflicts have been resolved.
  2. The relevant branch has been added to the test module.

Also, should the corresponding hashCode method be overridden?

我们还在评估影响范围。请确认:1.已解决所有冲突;2.已经在test模块中添加对应测试用例。
另外:是否需要重写对应的hashcode方法呢?

@psxjoy psxjoy requested review from psxjoy and Chat2DB-Pro December 18, 2024 02:24
@psxjoy psxjoy added the pending verification This problem needs to be confirmed label Dec 18, 2024
@psxjoy psxjoy changed the base branch from main to feature-1.x December 18, 2024 11:24
@psxjoy psxjoy added this to the 1.0.1 milestone Dec 18, 2024
@psxjoy
Copy link
Collaborator

psxjoy commented Dec 21, 2024

@fkong-bgl
Could you take a look at the conflicting files? For now, we’re planning to address this issue in the next version.

麻烦处理一下冲突文件,我们打算下个版本升级的时候修复这个问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending verification This problem needs to be confirmed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

建议@EqualsAndHashCode添加 exclude 或 of 参数 排除循环引用对象
2 participants