False positive S2095 with Spring beans should not be triggered

SonarQube 6.7.1:

@Bean
public Serde<MessageKey> getKeySerde() {
    final SpecificAvroSerde<MessageKey> serde = new SpecificAvroSerde<>();
    serde.configure(Colletions.singletonMap(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, "https://localhost:8080/"));
    return serde;
}

Gives:

Use try-with-resources or close this “SpecificAvroSerde” in a “finally” clause.

Spring Boot should take care of closing the bean when finalizing the application context. This should not be triggered.

Hi,

This rule already has some exclusion in place : could you provide a bit more detail about the type hierarchy of this SpecificAvroSerde class ? which type does it extends ?

Note that you can exclude this type to raise issues by configuring the rule with the excluded resource types (none excluded by default, but you can add type that don’t require checking for closing).