False positive S2095 with Spring beans should not be triggered


(PR) #1

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.