Skip to content

[Bug] Negative value in a date format aborts the read with ExcelDataConvertException #1116

Description

@nkuprins

Search before asking

  • I searched in the issues and found nothing similar.

Fesod version

main

JDK version

any

Operating system

Linux

Steps To Reproduce

File file = new File("negative-date.xlsx");

DataFormatData dataFormat = new DataFormatData();
dataFormat.setFormat("yyyy-mm-dd");

WriteCellData<BigDecimal> cell = new WriteCellData<>(new BigDecimal("-1"));
cell.getOrCreateStyle().setDataFormatData(dataFormat);

FesodSheet.write(file)
        .head(Collections.singletonList(Collections.singletonList("day")))
        .sheet()
        .doWrite(Collections.singletonList(Collections.singletonList(cell)));

System.out.println(FesodSheet.read(file).sheet().doReadSync());

Current Behavior

org.apache.fesod.sheet.exception.ExcelDataConvertException

A negative value is not a valid date, so DateUtils.getJavaDate returns null and that null
reaches Format.format. The whole read fails, not just the one cell.

Expected Behavior

[{0=-1}]

Anything else?

Found while writing the tests in #1110.

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions