PDF download in chrome

Hi,

I am using jmix 2.2.3. and I have problem downloading PDFs.
I am using following code to download PDF:

downloader.download(
    reportService.createReportFromResult(editedEntity),
    "report.pdf",
    DownloadFormat.PDF
)

pdf file is created in runtime as byte array. It is opened in new window and it is displayed correctly as expected and I am able to download report correctly in firefox. But in chrome, when I hit download button in newly opened window (that is displaying generated PDF) it downloads empty file with 0 bytes and I get following exception:

java.lang.NullPointerException: Cannot invoke "java.io.InputStream.read(byte[])" because "source" is null
	at com.vaadin.flow.server.StreamResource$Pipe.read(StreamResource.java:119) ~[flow-server-24.3.8.jar:24.3.8]
	at com.vaadin.flow.server.StreamResource$Pipe.copy(StreamResource.java:109) ~[flow-server-24.3.8.jar:24.3.8]
	at com.vaadin.flow.server.StreamResource$Pipe.accept(StreamResource.java:84) ~[flow-server-24.3.8.jar:24.3.8]
	at io.jmix.flowui.component.filedownloader.JmixFileDownloader.lambda$runCommand$18809115$1(JmixFileDownloader.java:121) ~[jmix-flowui-2.2.3.jar:na]
	at java.base/java.util.function.Consumer.lambda$andThen$0(Consumer.java:65) ~[na:na]
	at io.jmix.flowui.component.filedownloader.JmixFileDownloader.lambda$beforeClientResponseDownloadHandler$69016e48$1(JmixFileDownloader.java:158) ~[jmix-flowui-2.2.3.jar:na]
	at com.vaadin.flow.server.communication.SessionRequestHandler.handleRequest(SessionRequestHandler.java:64) ~[flow-server-24.3.8.jar:24.3.8]
	at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1574) ~[flow-server-24.3.8.jar:24.3.8]
	at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:398) ~[flow-server-24.3.8.jar:24.3.8]

omiting DownloadFormat.PDF has no effect.

It is happening both when running from IDE or when using compiled and deployed application.

Firefox version: 126.0
Chrome version: 124.0.6367.118
OS: Ubuntu 22.04 (both desktop and server where jmix app is deployed)

It works for me using Chrome 124.0.6367.208 and this code, which is the same as yours. I am running this from a custom action that is triggered by a button on a list screen.

byte[] pdf = new MemberPdf(resources).buildPdf(m);
downloader.download(pdf, "MemberCard.pdf", DownloadFormat.PDF);

This problem is still actual.
I tested it on ubuntu 24.04 and chrome version 126.0.6478.61 . Again, Firefox is working fine.
I tested it on macOs too on different computer. Same result in Chrome.

I still wasnt able to identify what could be a problem.

Hi,

I could reproduce the problem and created the GitHub issue.

1 Like