Call getDependents throws NullPointerException

Hi ,


I have attached the tempalte and the error has occured for the following code chain:

import com.aspose.cells.*;
import org.junit.Test;

import java.util.ArrayList;


public class DummyTest {

public class CustomFunction implements ICustomFunction
{
@Override
public Object calculateCustomFunction(String functionName, ArrayList paramsList, ArrayList contextObjects) {
return 1;
}
}

private void replaceFormula(Workbook wb, String cell, int sheetIndex) {
wb.getWorksheets().setActiveSheetIndex(sheetIndex);
Cells cells = wb.getWorksheets().get(sheetIndex).getCells();

String findString = cells.get(cell).getFormula();
FindOptions opt = new FindOptions();
opt.setRange(CellArea.createCellArea(0, 0, cells.getMaxRow(), cells.getMaxColumn()));
opt.setLookAtType(LookAtType.CONTAINS);
opt.setCaseSensitive(false);
opt.setSearchNext(true);
opt.setLookInType(LookInType.FORMULAS);
Cell findCell = cells.find(findString, null, opt);

if (findCell != null) {
String formula = findCell.getFormula().replace(’,’, ‘;’);
findCell.putValue(formula.substring(1), true);
}

}

private void invalidateCell(Cell cell, ICustomFunction resolver) {
// The below code line causes NullPointerException
Cell[] dependents = cell.getDependents(true);
if (cell.getFormula() != null) {
cell.calculate(true, resolver);
}

if (dependents != null) {
for (Cell dependedCell : dependents) {
invalidateCell(dependedCell, resolver);
}
}
}


public void testGetDependents() {
try {
Workbook wb = new Workbook(“D:\in.xlsx”);

CustomFunction customFunction = new CustomFunction();

replaceFormula(wb, “E1”, 0);
replaceFormula(wb, “E1”, 1);

// This method throws error, see details
invalidateCell(wb.getWorksheets().get(1).getCells().get(“E1”), customFunction);

System.out.println(“Success”);
} catch (Exception e) {
System.out.println(“Error”);
e.printStackTrace();
}

}

}

The output look as follows:

Error
java.lang.NullPointerException
at com.aspose.cells.bfr.c(Unknown Source)
at com.aspose.cells.ew.a(Unknown Source)
at com.aspose.cells.Cells.getDependents(Unknown Source)
at com.aspose.cells.Cell.getDependents(Unknown Source)
at com.asuproject.DummyTest.invalidateCell(DummyTest.java:41)
at com.asuproject.DummyTest.invalidateCell(DummyTest.java:48)
at com.asuproject.DummyTest.testGetDependents(DummyTest.java:65)


Could you scrutinize the issue and fix the problem?

We tested both Aspose.Cells 7.x and 8.0.1 versions, this bug is not fixed.

Thanks.

Hi,


Thanks for providing us template file and sample code.

After an initial test I observed the issue as you mentioned. I tested your scenario/ case using your sample code with your template file, i got the exception:
Error:
java.lang.NullPointerException
at com.aspose.cells.bfr.c(Unknown Source)
at com.aspose.cells.ew.a(Unknown Source)
at com.aspose.cells.Cells.getDependents(Unknown Source)
at com.aspose.cells.Cell.getDependents(Unknown Source)

I have logged a ticket with an id “CELLSJAVA-40797” for your issue. We will look into it soon.

Once we have any update on it, we will let you know here.

Thank you.

Hi,

Thanks for using Aspose.Cells.

Please download and try our latest version/fix: Aspose.Cells for Java v8.0.1.1


We have fixed your issue now.

Let us know your feedback.


Thank you.

The issues you have found earlier (filed as CELLSJAVA-40797) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.