Findbugs "Method may not hide stream" when using getResourceAsStream

If I have the following code in a servlet:

Properties p = new Properties();
p.load(getClass().getResourceAsStream("/test.properties"));

If I started the servlet through FindBugs, I would expect to receive an OS_OPEN_STREAM warning , but I will not. If I use a similar approach to open an arbitrary file in the file system (i.e. Not in the classpath), I get a Findbugs warning as expected:

Properties p = new Properties();
p.load(new FileInputStream(new File("c:/test.properties")));

In the first example, there is no warning, because Findbugs does not have a valid warning (i.e., should I close the stream in the finally block after loading into the Properties object), or is there a reason why I do not need to close the stream?

thank

Rich

+3
source share
1

:

- , ...

, . , Findbugs , , , .

, getResourceAsStream() , (.. ByteArrayInputStream). URLClassLoader , .

+7

Source: https://habr.com/ru/post/1756960/


All Articles