accumulo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Medinets <>
Subject FindBugs: INTEGER_MULTIPLY_CAST_TO_LONG question
Date Sat, 08 Sep 2012 12:40:14 GMT
accumulo.core.file.blockfile.cache.LruBlockCache, line 656

  public static long calculateOverhead(long maxSize, long blockSize,
int concurrency) {
((int) Math.ceil(maxSize * 1.2 / blockSize) *
        + (concurrency * ClassSize.CONCURRENT_HASHMAP_SEGMENT);

This code is flagged as:

 ICAST_INTEGER_MULTIPLY_CAST_TO_LONG: Result of integer multiplication
cast to long

This code performs integer multiply and then converts the result to a
long, as in:

    long convertDaysToMilliseconds(int days) { return 1000*3600*24*days; }

If the multiplication is done using long arithmetic, you can avoid the
possibility that the result will overflow. For example, you could fix
the above code to:

    long convertDaysToMilliseconds(int days) { return 1000L*3600*24*days; }


    static final long MILLISECONDS_PER_DAY = 24L*3600*1000;
    long convertDaysToMilliseconds(int days) { return days *


1. Can more of the value involved (say, ClassSize.CONCURRENT_HASHMAP) be longs?
2. How would this method be changed to resolve this message?
3. Can the multiplication steps be assigned to reasonably named
variables to self-document what is being added.
4. Can a comment be added why 1.2 is being used?
5. The overhead of what is being calculated?

View raw message