Hi @Eduardo_Ito,
We usually pick up the deprecation information as we parse the code and match the types and methods we encounter with classes found in the classpath.
Could it be that multiple versions of jackson-data-bind live within that classpath?
Could you run the analysis with debug logs enabled? That should give us an idea of whether were seeing the right version of the library.
I’ve encountered the same issue. I don’t think it’s to do with the multiple versions of Jackson-data-bind since the alternative method never been marked as deprecated since its first introduction.
I have the same issue in IntelliJ with SonarLint version 10.2.1.77304, the jackson-databind version is 2.15.3
/**
* Method for setting value of a field to specified String value.
*
* @return This node (to allow chaining)
*/
public ObjectNode put(String fieldName, String v) {
return _put(fieldName, (v == null) ? nullNode()
: textNode(v));
}
The SonarLink scan issue: “SonarLint: Remove this use of “put”; it is deprecated.”
I couldn’t reproduce the issue, and looking at the implementation and the previous answer, I’m not surprised. To continue the investigation, I will ask you to provide a reproducer.
It would be fantastic if you could zip a small project that reproduces your situation! It’s enough to have a maven or gradle project with the specific dependency you’re using and a class that uses the put method being reported as an issue.
Hi Angelo, here is an example that can be used to reproduce the SonarLint (Java:S1874) issue, the GitHub link is https://github.com/yumingtao/sonarlint-java-s1874.git, and it is reproduced in my local IntelliJ, here is the screenshot.
Since the getErrorCode() definition is unknown to the ECJ, because it was generated afterward by Lombok, it cannot infer the correct ObjectNode#put. I assume that ECJ picks the first definition found in com.fasterxml.jackson.databind.node.ObjectNode, which happens to be annotated as deprecated.
Wrapping up, your code is fine, so please ignore the issue reported. Alternatively, you could:
use directly the errorCode field instead of the getter
assign the value returned by getErrorCode() to a local variable (not specify the type explicitly, instead of using var)
Unfortunately, this is a nasty corner case caused by the combination of several different circumstances.