<div dir="ltr"><div class="gmail_default" style="font-family:monospace">And as a side note, I did some pretty in-depth research on the topic, and stumbled on this post on the lambda mailing list during Java 8's creation. I am adding it, as it seems to be considering many of the same concerns I have now.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace"><a href="https://mail.openjdk.org/pipermail/lambda-libs-spec-experts/2013-August/002195.html">https://mail.openjdk.org/pipermail/lambda-libs-spec-experts/2013-August/002195.html</a></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 3, 2024 at 10:00 PM David Alayachew <<a href="mailto:davidalayachew@gmail.com">davidalayachew@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div style="font-family:monospace" class="gmail_default"><br></div><div style="font-family:monospace" class="gmail_default">Hello Amber Dev Team and Core Libs Dev Team,<br><br>I am making my own implementation of java.util.stream.Stream that reads data from the internet lazily. It's basically java.nio.file.Files.lines(...), but the file is on the internet instead. Here is a StackOverflow post I made that basically gave birth to idea. Just for context. [1]<br><br>I used composition -- I held my resource and the stream inside of my container data type. However, I also had this container data type implement java.util.stream.Stream too. This way, the end user can use this object exactly like a Stream.<br><br>In my implementation, I delegated all method calls to the underlying stream. But, for each terminal operation, I would wrap the delegated calls with try-with-resources for my resources, to prevent resource leak upon exception.<br><br>Now, I know that this is taking an uphill path to a solution. We could easily tell the user that they have to close the resources themself. Or we could let the user provide their own resources and thus, leave the responsibility on their plate. Or we could use the escape-hatch provided by stream lol, and tell the user to use try-with-resources on my custom stream. As you all intended us to do, I'm sure.<br><br>I know the reason might seem poorly justified (StackOverflow told me as much -- [1]), but I did this so that none of the users of my stream would have to concern themselves doing try-with-resources. Try-with-resources is an excellent utility, but I have no way to know if I left a resource unclosed because there are no compiler warnings or errors if I do so.<br><br>Are there any plans to make it easier to detect potential resource leaks? Ideally with a compiler warning or error?<br><br>Thank you for your time and help!<br>David Alayachew<br><br>[1] = <a href="https://stackoverflow.com/questions/77959436" target="_blank">https://stackoverflow.com/questions/77959436</a></div><div style="font-family:monospace" class="gmail_default"><br></div></div>
</blockquote></div>