Bug 45645 - autoSizeColumn() works incorrectly for large widths (cf. bug #43090)
Summary: autoSizeColumn() works incorrectly for large widths (cf. bug #43090)
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-dev
Hardware: PC Windows Server 2003
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-18 06:55 UTC by Norbert Schenk
Modified: 2008-08-18 11:34 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Norbert Schenk 2008-08-18 06:55:26 UTC
Preliminary note: This bug is in 3.1-FINAL, but the latest version the Combo Box did offer was 3.0-dev

In HSSFSheet.autoSizeColumns(), the following code:

if (width != -1) {
    if (width > Short.MAX_VALUE) { //width can be bigger that Short.MAX_VALUE!
        width = Short.MAX_VALUE;
    }
    sheet.setColumnWidth(column, (short) (width * 256));
}

should be replaced by:

if (width != -1) {
    width *= 256;
    if (width > Short.MAX_VALUE) { //width can be bigger that Short.MAX_VALUE!
        width = Short.MAX_VALUE;
    }
    sheet.setColumnWidth(column, (short) (width));
}

which is probably what was intended, since only then the cast to short will always have an argument that is within range.

With the original version, large widths produce settings which depend on the least significant bits and thus tend to be rather random.

The topic has already be addressed in bug #43090, but the resolution which made it into the final version does not solve the problem.
Comment 1 Yegor Kozlov 2008-08-18 11:34:26 UTC
Thanks for pointing it out. Of course, multiplication should be done before checking Short.MAX_VALUE.
Fixed in r686844.

Yegor