- versions used: https://sonarcloud.io
- error observed:
https://sonarcloud.io/project/issues?id=pdfbox-reactor&issues=AXBxujxrkDwSqnoGfjXf&open=AXBxujxrkDwSqnoGfjXf
the code below is flagged as smelly (S3824) because Map.computeIfAbsent() is not used:
raster.getPixel(x, y, samples);
hash = Float.floatToIntBits(samples[0]);
int [ ] rgb = calculatedValues.get(hash);
if (rgb == null)
{
samples[0] /= 255;
float[ ] altColor = tintTransform.eval(samples);
float[ ] fltab = alternateColorSpace.toRGB(altColor);
rgb = new int[3];
rgb[0] = (int) (fltab[0] * 255);
rgb[1] = (int) (fltab[1] * 255);
rgb[2] = (int) (fltab[2] * 255);
calculatedValues.put(hash, rgb);
}
However the two methods (eval() and toRGB()) may throw an IOException, so this shouldn’t be flagged IMHO, because it isn’t possible to use computerIfAbsent() except when making the code much more complex.
-
steps to reproduce
run SonarCloud on the Apache PDFBox project. Search fororg.apache.pdfbox.pdmodel.graphics.color.PDSeparation
. -
potential workaround
suppress the warning