Skip to main content
Filter by
Sorted by
Tagged with
-2 votes
1 answer
196 views

I'm working on a Java utility. This utility should read some input files (one or several). Each input file contains three types of strings, representing an integer, a float, and a string. The utility ...
longpastgone's user avatar
4 votes
2 answers
256 views

I have been using try-with-resources a lot. I use it for database resource types or File stuff all the time to close the resource. Now, I am using POI for large Excel files, and I am just noticing ...
SedJ601's user avatar
  • 14k
0 votes
1 answer
202 views

MOTIVATION On a youtube video of Venkat Subramaniam, he tells about how not use AutoCloseable, but try to use a function like "use". Because, one may forget to implement try block on a class ...
Tugalsan Karabacak's user avatar
0 votes
1 answer
414 views

Does any major Java library offer a AutoCloseable like interface for which close method doesn't throw exception? My close implementation is very simple and I'd like to avoid the boilerplate of ...
Hanna Khalil's user avatar
  • 1,075
1 vote
1 answer
582 views

I want to return an autocloseable object inside a CompletableFuture and use it in whenComplete without going to close it manually later. This is the code that I've tried, but of course it won't work ...
renvins's user avatar
  • 33
0 votes
1 answer
414 views

I'm reading Effective Java by Joshua Bloch. In ITEM 8: AVOID FINALIZERS AND CLEANERS of CHAPTER 2, he highlights the problems with using finalizers and cleaners for memory management. This article by ...
Rahul's user avatar
  • 877
-2 votes
1 answer
1k views

public class CloseableResource implements AutoCloseable { private static boolean _closed = false; int _n; public CloseableResource(int n){ } public void use() throws Exception{ ...
Gabriel N's user avatar
1 vote
1 answer
920 views

This must be simple, but I've been banging my head against it for half an hour now... Here's my old, exception-unsafe code: fun isReady(): Boolean { try { val cc: CommandChannel = ...
Quuxplusone's user avatar
  • 28.7k
0 votes
2 answers
278 views

I currently face the problem of correctly closing resources that never leave their containing Either. The relevant code looks something like this: object SomeError class MyRes : AutoCloseable { [...] }...
Kolja's user avatar
  • 1,247
0 votes
1 answer
95 views

For example Scanner class, which implements Closeable interface: Scanner sc = new Scanner(...); sc.//do smthing sc = new Scanner(...); <- is previous Scanner closed? Does it create memory leak? sc./...
MarekChr's user avatar
  • 1,174
0 votes
1 answer
1k views

How to return error in springboot and close a Closeable class? When I got some error in springboot and close a closable class is returning 200 OK don't I need close the Closeable? Is there some way to ...
Dilermando Lima's user avatar
0 votes
1 answer
740 views

Since JavaMail version 1.6.0 classes Store and Folder (amongst Transport) should implement AutoClosable interface. I did not find any examples of someone using JavaMail API with auto-closable. After a ...
Filou's user avatar
  • 577
0 votes
1 answer
402 views

I have been working with try-with-resources statement. try(FileReader rd = new FileReader("Test.txt");){} catch (Exception e) {e.printStackTrace();} The benefit of using try with resources ...
Sufian's user avatar
  • 1
4 votes
1 answer
3k views

I am trying to correctly write an aws lambda using Java that will use aws sdk SqsClient and SnsClient. I see that these clients implement close() method, and it is generally a good practice to call ...
Anastasia Drozhzha's user avatar
5 votes
1 answer
4k views

Given a class MyClass using an internal closeable object, myCloseable and providing a method getCloseable() that returns it; Eclipse, if configured for this kind of closeable resource warnings, will ...
Olivier Cailloux's user avatar
0 votes
1 answer
172 views

I am using: openshift AMQ (seems to be a forked activemq-5.11.0.redhat...... version) EAP 7.2.3 While local debugging I get as Connection some ~ConnectionProxy with a physical ...
user1782357's user avatar
3 votes
2 answers
553 views

public ResultSet executeQuery(String query) { return session.call(query) } public List<Record> findRecords(String name) { String query = prepareQuery(name); return mapResultToRecord(...
6harat's user avatar
  • 632
2 votes
1 answer
1k views

Suppose we need to create a Flux based on contents of a Closeable resource. For clarity say there is a BufferedReader to be converted to Flux<String>. BufferedReader reader = createReader("...
diziaq's user avatar
  • 7,895
7 votes
3 answers
1k views

I have a java class that holds a Closeable resource internally. This means my class also implements the Closeable interface and closes the internal resource in its own close() method. What is the ...
Gyorgy Szekely's user avatar
1 vote
1 answer
394 views

I have a class that takes a local file, transforms it, and stores it in GCS: import java.nio.channels.Channels import java.nio.file.{ Files, Path } import java.util.zip.{ GZIPOutputStream, ...
Etienne Neveu's user avatar
10 votes
1 answer
910 views

Background: I use the Java class InitialDirContext to access LDAP directories. Unfortunately, it does not implement interface AutoCloseable, so it cannot be used in try-with-resources blocks. Here ...
kevinarpe's user avatar
  • 21.6k
8 votes
3 answers
2k views

I am creating a variable amount of AutoCloseable objects in a try-with-resources block. At any point of exit, I want all of the allocated resources closed. I can imagine writing something myself to ...
Ryan Haining's user avatar
  • 37.2k
1 vote
2 answers
1k views

Can someone please explain to me what is happening here and in which order?. The output doesn't make any sense to me. The output is T 1 IOE F. The code is: import java.io.Closeable; import java.io....
jivko's user avatar
  • 430
2 votes
1 answer
2k views

In the code below I try to access my other constructor that takes a InputStream... However I need to somehow close this stream to avoid resource leaks. If I try to put a try catch around, it will ...
AgentM's user avatar
  • 406
31 votes
5 answers
12k views

I am authoring a java library. Some of the classes that are meant to be used by library users, hold native system resources (over JNI). I'd like to ensure that the user "disposes" these objects, as ...
haelix's user avatar
  • 4,655