commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <j...@apache.org>
Subject [jira] [Created] (IMAGING-152) MedianCutQuantizer.process - odd code: updates field before potentially throwing Exception
Date Thu, 01 Jan 2015 23:13:13 GMT
Sebb created IMAGING-152:
----------------------------

             Summary: MedianCutQuantizer.process - odd code: updates field before potentially
throwing Exception
                 Key: IMAGING-152
                 URL: https://issues.apache.org/jira/browse/IMAGING-152
             Project: Commons Imaging
          Issue Type: Bug
            Reporter: Sebb


MedianCutQuantizer.process has some odd code

{code}
final int[] palette = new int[paletteSize];
for (int i = 0; i < colorGroups.size(); i++) {
    final ColorGroup colorGroup = colorGroups.get(i);
    palette[i] = colorGroup.getMedianValue(); // (A)
    colorGroup.paletteIndex = i; // (B)
    if (colorGroup.colorCounts.size() < 1) {
       throw new ImageWriteException("empty color_group: "
                + colorGroup);
    }
}
{code}

The code at (A) is useless if the Exception is thrown, so should be after the conditional.

I'm not sure about the code at (B) - does it make sense to update the colorGroup before throwing
the Exception? Is it needed to mark the group in some way? If so, the purpose should be documented



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message