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

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

Open
fkong-bgl opened this issue Nov 26, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@fkong-bgl
Copy link

建议先去看文档

快速开始常见问题

触发场景描述

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 fkong-bgl added the bug Something isn't working label Nov 26, 2024
@fkong-bgl
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants