Hi, **the following error occurs when trying to display a pdf stored in src

Hi,
the following error occurs when trying to display a pdf stored in src/main/resources

2020-10-05 19:37:50.719 ERROR 27620 --- [nio-8081-exec-9]
 s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request 
[/VAADIN/dynamic/resource/1/effbb15d-02b7-4ae4-ac1d-4e58a506b6ee/AnyFile.pdf] and exception [java.lang.NullPointerException]
 as the response has already been committed. As a result, the response may have the wrong status code.

And here is the source code

printPdf.addClickListener(e -> {
	Dialog dialog = new Dialog();
                    
	StreamResource streamResource = new StreamResource("AnyFile.pdf",
		this::getInputStream);
                    
	streamResource.setContentType("application/pdf");
	streamResource.setCacheTime(0);
                    
	PdfBrowserViewer pdfBrowserViewer = new PdfBrowserViewer(streamResource);
	pdfBrowserViewer.setHeight("100%");

	PdfBrowserViewer viewer = new PdfBrowserViewer(streamResource);
                                        
	viewer.setHeight("700px");
	viewer.setWidth("700px");
                    
	dialog.add(viewer);
	dialog.open();
                    
	});

}          

InputStream getInputStream() {
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream("Invoice-2019-02.pdf");
            
        } catch (FileNotFoundException e) {
            System.out.println("File not found");
            e.printStackTrace();
        }
        System.out.println("File is here");
        return inputStream;
}    

Could you help me please ?
Many thanks in advance

The exception comes from a class I do not know, so maybe check there? Also did you try this https://github.com/alejandro-du/pdf-browser/blob/f99e7586a75c9e70b11ce1d54de413cc5f79bc9c/src/test/java/org/vaadin/alejandro/DemoView.java#L13 ?