Sonarqube not detecting Memory Leak Issue

Hi team,

We are using SonarQube for Java our project. In our code developers are using below line,

this.jsonHttpService.createClient(this.madHttpClient, MadApiClient.class);

This line will create one client through which we will send the request to 3pp. After that we are not closing this client, once got the response from 3pp. when there is more traffic, for each request client will be created, which has caused memory leakage issue and all threats were consumed which caused emergency in our Project.

If the client is opening the code, in sonarqube can we scan it if it is closed properly so that we can avoid such memory leak issues?
Can you suggest which rule/plugin can be used for this?

Regards,
Sahana M K

Hi Sahana,

Welcome to the community!

Does the client implement Closeable?

 
Ann

Hi Ann,
NO, dev member forgot to implement AutoCloseables.close(this.httpClient) for these client creation cases. Which should be detected during code scanning for created clients.

Regards,
Sahana M K

Hi Sahana,

I believe the rule that looks for unclosed resources keys off them being Closeable. Is there any other attribute of the client that you believe could/should have been a marker for the rule?

 
Ann

Hi Ann,

Can you check for a rule with AutoCloseables ?
Or check if we can configure any plugins for that?

Regards,
Sahana M K

Hi Sahana,

Are you asking which rule checks that? That would be S2095.

 
HTH,
Ann

Hi Ann,

We are already using that rule in our quality profile, but still the issue was not detected in sonarqube analysis. Can you suggest why it happened and what can be done as alternative solution to detect such issues?

Regards,
Sahana M K

Hi Sahana,

Per the description, that rule looks for un-closed instances of Closeables or AutoCloseables. Your developer forgot to implement the interface, so the resource simply wasn’t eligible to be detectedby the rule. That’s why I asked if there was any other characteristic that you believe the rule could have keyed off of. Closeable-ness, auto or not, is already covered. What else should be covered?

Or perhaps there should be a different rule? Something like “Classes that [do X] should implement Closeable”? Of course, you’ll need to define the “do X” part here.

 
Ann