Skip to content

Commit

Permalink
fix #234 when return null reference
Browse files Browse the repository at this point in the history
  • Loading branch information
ozlerhakan committed Aug 14, 2022
1 parent 2e9827c commit cd618e5
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/main/java/com/poiji/bind/mapping/PoijiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ public void endRow(int rowNum) {

@Override
public void cell(String cellReference, String formattedValue, XSSFComment comment) {
if (cellReference == null) {
// TODO hidden log required; a cell reference could return null
return;
}
final CellAddress cellAddress = new CellAddress(cellReference);
int row = cellAddress.getRow();
int headerStart = options.getHeaderStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public void startElement(String uri, String localName, String qName, Attributes
int styleIndex = Integer.parseInt(cellStyleStr);

if (poijiOptions.isDisableXLSXNumberCellFormat()) {
attributes2.removeAttribute(styleIndex);
if (attributes2.getLength() > styleIndex) {
attributes2.removeAttribute(styleIndex);
}
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/com/poiji/deserialize/NullReferenceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.poiji.deserialize;

import com.poiji.bind.Poiji;
import com.poiji.deserialize.model.AutoImport;
import com.poiji.option.PoijiOptions;
import org.junit.Test;

import java.io.File;
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertNotNull;

public class NullReferenceTest {

@Test
public void shouldReturnEmptyWhenCellReferenceNull() {
PoijiOptions options = PoijiOptions.PoijiOptionsBuilder.settings().disableXLSXNumberCellFormat().build();

List<AutoImport> result = Poiji.fromExcel(new File("src/test/resources/autos2.xlsx"), AutoImport.class, options);

assertNotNull(result);
assertThat(result.size(), is(20));

}
}
58 changes: 58 additions & 0 deletions src/test/java/com/poiji/deserialize/model/AutoImport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.poiji.deserialize.model;

import com.poiji.annotation.ExcelCell;
import com.poiji.annotation.ExcelCellName;

import java.time.LocalDate;

public class AutoImport {

@ExcelCellName(value = "fabricacion", mandatory = false)
private LocalDate fecha;

@ExcelCell(0)
private String clase;

@ExcelCell(1)
private String tipo;

@ExcelCell(2)
private String subtipo;

@ExcelCell(3)
private String marca;

@ExcelCell(4)
private String modelo;

@ExcelCell(5)
private String submodelo;

@ExcelCell(6)
private String dsc;

@ExcelCell(7)
private String pmercado;

@ExcelCell(8)
private Double ptoma;

@ExcelCell(9)
private String anio;

@ExcelCell(10)
private String cil;

@ExcelCell(11)
private String com;

@ExcelCell(12)
private String tp;

@ExcelCell(13)
private Integer pasajeros;

@ExcelCell(14)
private Integer puertas;

}

0 comments on commit cd618e5

Please sign in to comment.