https://bz.apache.org/bugzilla/show_bug.cgi?id=65917

            Bug ID: 65917
           Summary: Image insertion fails
           Product: POI
           Version: 5.2.0-FINAL
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XWPF
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

Hey,
I am currently working on a project heavily utilizing Apache POI.
In one use case, we need to insert a table into an XWPF document, and in each
cell we insert a QR-Code.
I wrote a test for this verifying the behavior, which normally goes through
without problems. When running the full test suite (~75 tests), this test fails
though in about 50% of the time, with the following exception:
```
java.util.concurrent.CompletionException: java.lang.NullPointerException:
Cannot invoke
"org.apache.poi.openxml4j.opc.OPCPackage.getPart(org.apache.poi.openxml4j.opc.PackagePartName)"
because the return value of
"org.apache.poi.xwpf.usermodel.XWPFDocument.getPackage()" is null.
```

The insertion code is:
```
    try (var in = Files.newInputStream(path, StandardOpenOption.READ)) {
      return paragraph.createRun()
          .addPicture(in, contentType, path.getFileName().toString(),
dim.width, dim.height);
    } catch (InvalidFormatException | IOException e) {
      logger.error("Could not insert image from given Path
%s.".formatted(path), e);
      throw new IllegalArgumentException("Could not insert image form given
Path.", e);
    }
```

I have other use cases where I use this method, also verified through testing,
where this exception does not get thrown.
Does somebody know what the problem here is/how to fix it?
Best regards
Anton

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to