S3824 Suggestion to use "Map.computeIfAbsent()" should consider checked exceptions

    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 for org.apache.pdfbox.pdmodel.graphics.color.PDSeparation.

  • potential workaround
    suppress the warning

Hi Tilman,
Yes, it’s a false-positive. I created this ticket SONARJAVA-3303.
Thanks for your feedback, have a nice day.

1 Like