When executing the following code, it results in a NullPointerException. It is supposed to copy the content of cells from another workbook sheet into `workbook`. Calling `setCellFormula(String)` without the external reference does work. ```scala import org.apache.poi.ss.usermodel.CellType import org.apache.poi.xssf.usermodel.XSSFWorkbook object Main { def main(args: Array[String]): Unit = { val workbook = new XSSFWorkbook() val evaluator = workbook.getCreationHelper.createFormulaEvaluator() evaluator.setIgnoreMissingWorkbooks(true) val sheet = workbook.createSheet("sheet") val row = sheet.createRow(0) val cell = row.createCell(0, CellType.FORMULA) try { cell.setCellFormula(f"[some-workbook-that-does-not-yet-exist.xlsx]main!B:D") } catch { case e: Throwable => e.printStackTrace() } } } ``` Here is the Stacktrace : ``` java.lang.NullPointerException at org.apache.poi.xssf.usermodel.BaseXSSFEvaluationWorkbook.findExternalLinkIndex(BaseXSSFEvaluationWorkbook.java:140) at org.apache.poi.xssf.usermodel.BaseXSSFEvaluationWorkbook.resolveBookIndex(BaseXSSFEvaluationWorkbook.java:114) at org.apache.poi.xssf.usermodel.BaseXSSFEvaluationWorkbook.get3DReferencePtg(BaseXSSFEvaluationWorkbook.java:268) at org.apache.poi.ss.formula.FormulaParser.createAreaRefParseNode(FormulaParser.java:992) at org.apache.poi.ss.formula.FormulaParser.parseRangeable(FormulaParser.java:528) at org.apache.poi.ss.formula.FormulaParser.parseRangeExpression(FormulaParser.java:322) at org.apache.poi.ss.formula.FormulaParser.parseSimpleFactor(FormulaParser.java:1548) at org.apache.poi.ss.formula.FormulaParser.percentFactor(FormulaParser.java:1506) at org.apache.poi.ss.formula.FormulaParser.powerFactor(FormulaParser.java:1493) at org.apache.poi.ss.formula.FormulaParser.Term(FormulaParser.java:1867) at org.apache.poi.ss.formula.FormulaParser.additiveExpression(FormulaParser.java:1994) at org.apache.poi.ss.formula.FormulaParser.concatExpression(FormulaParser.java:1978) at org.apache.poi.ss.formula.FormulaParser.comparisonExpression(FormulaParser.java:1935) at org.apache.poi.ss.formula.FormulaParser.intersectionExpression(FormulaParser.java:1908) at org.apache.poi.ss.formula.FormulaParser.unionExpression(FormulaParser.java:1889) at org.apache.poi.ss.formula.FormulaParser.parse(FormulaParser.java:2036) at org.apache.poi.ss.formula.FormulaParser.parse(FormulaParser.java:170) at org.apache.poi.xssf.usermodel.XSSFCell.setFormula(XSSFCell.java:553) at org.apache.poi.xssf.usermodel.XSSFCell.setCellFormulaImpl(XSSFCell.java:529) at org.apache.poi.ss.usermodel.CellBase.setCellFormula(CellBase.java:126) at Main$.main(Main.scala:25) at Main.main(Main.scala) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at sbt.Run.invokeMain(Run.scala:133) at sbt.Run.execute$1(Run.scala:82) at sbt.Run.$anonfun$runWithLoader$5(Run.scala:110) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:17) at sbt.TrapExit$App.run(TrapExit.scala:258) at java.base/java.lang.Thread.run(Thread.java:834) ```
I tried with latest trunk code and did not get a NPE. I got this: java.lang.RuntimeException: Book not linked for filename some-workbook-that-does-not-yet-exist.xlsx
I don't know what changes were made between version 5.0.0 and 5.1,0 but updating to version to 5.1.0 solves the NullPointerException and gets me the RuntimeException PJ Fanning is getting. Thank you for your help.