Community
Participate
Working Groups
This worked fine in Eclipse 2019.06 but has been broken in each version since. This affects us as we have many "cached" resources that are giving false positives potentially masking real issues if we need to mark all the false positives to ignore. Example code. We have a wrapper class that encapsulates a resource, here we just keep it for the life of application and provide a reference to any other class that needs it. Note we provide the reference in two ways. package test_utilities; import javax.sql.DataSource; public class ExampleResourceWrapper { private static ExampleResource internalDataSourceSingleton; public ExampleResourceWrapper() { initialise(); } private static void initialise() { if (internalDataSourceSingleton == null) { // Keeps the database open until we shutdown internalDataSourceSingleton = new ExampleResource(); } } public static DataSource getDataSource1() { return internalDataSourceSingleton; } public static ExampleResource getDataSource2() { return internalDataSourceSingleton; } } The ExampleResource class just subclasses the AutoCloseable class to show the issue. package test_utilities; import org.apache.commons.dbcp2.BasicDataSource; public class ExampleResource extends BasicDataSource { // Just a wrapper } Here's some code using the cached resource and showing the issue: package test_utilities; import javax.sql.DataSource; public class ExampleResourceLeak { public static void main(String[] args) { // As expected no warning here DataSource ds1 = ExampleResourceWrapper.getDataSource1(); // False positive "potential resource leak" warning here DataSource ds2 = ExampleResourceWrapper.getDataSource2(); // Code just to remove the not used warning ds1.getClass(); ds2.getClass(); } } So why does ExampleResourceWrapper.getDataSource1() work as expected and not show an error but ExampleResourceWrapper.getDataSource2() shows the False positive "potential resource leak" warning.
May be duplicate of bug 565205
(In reply to Sravan Kumar Lakkimsetti from comment #1) > May be duplicate of bug 565205 I don't think it is a duplicate of that bug. Bug 565205 is caused by the resource actually not being freed. For this issue the resource is freed, where the warning is raised we are not "opening/creating" the resource (rather just getting a reference to it) so should not be expected to close the resource - yet we get a warning the the resource is not closed.
Any progress on this? This is a real problem for us - we develop a highly distributed system with many ports that deals with many files, sockets, database etc - it is important to us that we get warning of potential resource leaks. Having so many false positive warnings prevent us from upgrading our Eclipse versions and we are now a couple of years behind and would prefer to use the latest Eclipse.
Chasing this again - it would be great if someone could take a look at this as we would like to upgrade the version of Eclipse we use yet can't if we get all these false positives due to the risk of these masking an real issue.
Chasing again - is this not a problem for many users? Surely it makes the "Potential Resource Leak" check useless in Eclipse?
The issue still exists in Eclipse 2022-12.