aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2019-09-14 09:54:11 +0000
committerPJ Fanning <fanningpj@apache.org>2019-09-14 09:54:11 +0000
commitdc6a4a99e2d077ff9c9a343e218070d4df14d48d (patch)
tree2f0a8a12f9c20dcaa8e7e1b7da168c0dcf44782f /src/java/org/apache/poi
parent8a9af96f953d1536a60c8bb667da91b4b5b5dc20 (diff)
downloadpoi-dc6a4a99e2d077ff9c9a343e218070d4df14d48d.tar.gz
poi-dc6a4a99e2d077ff9c9a343e218070d4df14d48d.zip
try to avoid casting to int
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1866933 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi')
-rw-r--r--src/java/org/apache/poi/hpsf/Section.java16
-rw-r--r--src/java/org/apache/poi/ss/formula/atp/ParityFunction.java2
-rw-r--r--src/java/org/apache/poi/ss/util/CellReference.java2
-rw-r--r--src/java/org/apache/poi/ss/util/ExpandedDouble.java2
-rw-r--r--src/java/org/apache/poi/ss/util/IEEEDouble.java2
-rw-r--r--src/java/org/apache/poi/util/HexDump.java2
6 files changed, 13 insertions, 13 deletions
diff --git a/src/java/org/apache/poi/hpsf/Section.java b/src/java/org/apache/poi/hpsf/Section.java
index 0c1bcf263d..5c78402701 100644
--- a/src/java/org/apache/poi/hpsf/Section.java
+++ b/src/java/org/apache/poi/hpsf/Section.java
@@ -182,10 +182,10 @@ public class Section {
final TreeBidiMap<Long,Long> offset2Id = new TreeBidiMap<>();
for (int i = 0; i < propertyCount; i++) {
/* Read the property ID. */
- long id = (int)leis.readUInt();
+ long id = leis.readUInt();
/* Offset from the section's start. */
- long off = (int)leis.readUInt();
+ long off = leis.readUInt();
offset2Id.put(off, id);
}
@@ -196,7 +196,7 @@ public class Section {
int codepage = -1;
if (cpOffset != null) {
/* Read the property's value type. It must be VT_I2. */
- leis.setReadIndex((int)(this._offset + cpOffset));
+ leis.setReadIndex(Math.toIntExact(this._offset + cpOffset));
final long type = leis.readUInt();
if (type != Variant.VT_I2) {
@@ -221,7 +221,7 @@ public class Section {
}
int pLen = propLen(offset2Id, off, size);
- leis.setReadIndex((int)(this._offset + off));
+ leis.setReadIndex(Math.toIntExact(this._offset + off));
if (id == PropertyIDMap.PID_DICTIONARY) {
leis.mark(100000);
@@ -242,7 +242,7 @@ public class Section {
}
}
- sectionBytes.write(src, (int)_offset, size);
+ sectionBytes.write(src, Math.toIntExact(_offset), size);
padSectionBytes();
}
@@ -261,7 +261,7 @@ public class Section {
Long nextKey = offset2Id.nextKey(entryOffset);
long begin = entryOffset;
long end = (nextKey != null) ? nextKey : maxSize;
- return (int)(end - begin);
+ return Math.toIntExact(end - begin);
}
@@ -823,7 +823,7 @@ public class Section {
/* Read the string - Strip 0x00 characters from the end of the string. */
int cp = (codepage == -1) ? Property.DEFAULT_CODEPAGE : codepage;
- int nrBytes = (int)((sLength-1) * (cp == CodePageUtil.CP_UNICODE ? 2 : 1));
+ int nrBytes = Math.toIntExact(((sLength-1) * (cp == CodePageUtil.CP_UNICODE ? 2 : 1)));
if (nrBytes > 0xFFFFFF) {
LOG.log(POILogger.WARN, errMsg);
isCorrupted = true;
@@ -946,7 +946,7 @@ public class Section {
for (Property aPa : pa) {
hashCode += aPa.hashCode();
}
- return (int) (hashCode & 0x0ffffffffL);
+ return Math.toIntExact(hashCode & 0x0ffffffffL);
}
diff --git a/src/java/org/apache/poi/ss/formula/atp/ParityFunction.java b/src/java/org/apache/poi/ss/formula/atp/ParityFunction.java
index 29012fe18c..b59b4808b5 100644
--- a/src/java/org/apache/poi/ss/formula/atp/ParityFunction.java
+++ b/src/java/org/apache/poi/ss/formula/atp/ParityFunction.java
@@ -62,6 +62,6 @@ final class ParityFunction implements FreeRefFunction {
d = -d;
}
long v = (long) Math.floor(d);
- return (int) (v & 0x0001);
+ return Math.toIntExact(v & 0x0001);
}
}
diff --git a/src/java/org/apache/poi/ss/util/CellReference.java b/src/java/org/apache/poi/ss/util/CellReference.java
index 6e6dbe678d..9f88bcaecb 100644
--- a/src/java/org/apache/poi/ss/util/CellReference.java
+++ b/src/java/org/apache/poi/ss/util/CellReference.java
@@ -354,7 +354,7 @@ public class CellReference {
if(rowNum > Integer.MAX_VALUE) {
return false;
}
- return isRowWithinRange((int)rowNum, ssVersion);
+ return isRowWithinRange(Math.toIntExact(rowNum), ssVersion);
}
/**
diff --git a/src/java/org/apache/poi/ss/util/ExpandedDouble.java b/src/java/org/apache/poi/ss/util/ExpandedDouble.java
index 24ef95cacc..40d4066af8 100644
--- a/src/java/org/apache/poi/ss/util/ExpandedDouble.java
+++ b/src/java/org/apache/poi/ss/util/ExpandedDouble.java
@@ -54,7 +54,7 @@ final class ExpandedDouble {
private final int _binaryExponent;
public ExpandedDouble(long rawBits) {
- int biasedExp = (int) (rawBits >> 52);
+ int biasedExp = Math.toIntExact(rawBits >> 52);
if (biasedExp == 0) {
// sub-normal numbers
BigInteger frac = BigInteger.valueOf(rawBits).and(BI_FRAC_MASK);
diff --git a/src/java/org/apache/poi/ss/util/IEEEDouble.java b/src/java/org/apache/poi/ss/util/IEEEDouble.java
index f5a42edca6..91d8fea434 100644
--- a/src/java/org/apache/poi/ss/util/IEEEDouble.java
+++ b/src/java/org/apache/poi/ss/util/IEEEDouble.java
@@ -39,6 +39,6 @@ final class IEEEDouble {
* @return the top 12 bits (sign and biased exponent value)
*/
public static int getBiasedExponent(long rawBits) {
- return (int) ((rawBits & EXPONENT_MASK) >> EXPONENT_SHIFT);
+ return Math.toIntExact((rawBits & EXPONENT_MASK) >> EXPONENT_SHIFT);
}
}
diff --git a/src/java/org/apache/poi/util/HexDump.java b/src/java/org/apache/poi/util/HexDump.java
index d3edc2843f..5afd1dbe18 100644
--- a/src/java/org/apache/poi/util/HexDump.java
+++ b/src/java/org/apache/poi/util/HexDump.java
@@ -401,7 +401,7 @@ public class HexDump {
char[] buf = new char[nDigits];
long acc = value;
for(int i=nDigits-1; i>=0; i--) {
- int digit = (int)(acc & 0x0F);
+ int digit = Math.toIntExact(acc & 0x0F);
buf[i] = (char) (digit < 10 ? ('0' + digit) : ('A' + digit - 10));
acc >>>= 4;
}