vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
618 stars 167 forks source link

Allow InputStreamFactory.createInputStream() to throw IOException #18293

Open mvysny opened 10 months ago

mvysny commented 10 months ago

Describe your motivation

InputStreamFactory.createInputStream() creates an input stream. Since both reading and creating an input stream may throw IOException, it would be good to add the "throws IOException" clause to the createInputStream() function. For example:

        VaadinSession.getCurrent().getResourceRegistry().registerResource(new StreamResource("demo.pdf", () -> new FileInputStream("/home/mavi/Downloads/demo.pdf")));

This code doesn't compile because new FileInputStream() may throw a FileNotFoundException.

Describe the solution you'd like

Change the createInputStream() declaration to InputStream createInputStream() throws IOException.

Describe alternatives you've considered

-

Legioth commented 2 months ago

Adding an exception would be a breaking change in the hypothetical case that code in some application or 3rd party add-on would directly call that method rather than only using it to create a regular StreamResource instance.