alibaba / easyexcel

快速、简洁、解决大文件内存溢出的java处理Excel工具
https://easyexcel.opensource.alibaba.com
Apache License 2.0
32.82k stars 7.59k forks source link

关于使用@EqualsAndHashCode Scala3调用会导致 java.lang.StackOverflowError #4053

Open fkong-bgl opened 1 week ago

fkong-bgl commented 1 week ago

建议先去看文档

快速开始常见问题

触发场景描述

Scala2 升级scale3后出现 hashCoded导致的StackOverflowError

触发Bug的代码

class ExportData(
field1: String,
  field2: String,
  description: Option[String] // 使用Option 导致hashCode死循环
) {
  def getField1() = field1

  def getField2() = field2

  def getDescription(): Option[String] = description
}

class SimpleTest {

  val exportData = List(
    new ExportData("data1", "data2", Some("abc")),

  )

  @Test
  def test(): Unit = {
    EasyExcelFactory.write("out2.csv", classOf[ExportData])
      .excelType(ExcelTypeEnum.CSV)
      .sheet("Sheet1")
      .doWrite(exportData.asJava)
  }
}

提示的异常或者没有达到的效果

java.lang.StackOverflowError at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.excel.metadata.csv.CsvWorkbook.hashCode(CsvWorkbook.java:36) at com.alibaba.excel.metadata.csv.CsvSheet.hashCode(CsvSheet.java:60) at com.alibaba.

fkong-bgl commented 1 week ago

解决方案:@EqualsAndHashCode添加 exclude 或 of 参数 排除循环引用对象