From: Andreas Beeker Date: Mon, 17 Apr 2017 11:02:22 +0000 (+0000) Subject: findbugs fixes X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7df2a8804c89d8b52f9cbef2840e86c7e129e675;p=poi.git findbugs fixes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1791679 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/ss/formula/ConditionalFormattingEvaluator.java b/src/java/org/apache/poi/ss/formula/ConditionalFormattingEvaluator.java index a06ac0879d..adabc09f58 100644 --- a/src/java/org/apache/poi/ss/formula/ConditionalFormattingEvaluator.java +++ b/src/java/org/apache/poi/ss/formula/ConditionalFormattingEvaluator.java @@ -109,7 +109,10 @@ public class ConditionalFormattingEvaluator { protected List getRules(Sheet sheet) { final String sheetName = sheet.getSheetName(); List rules = formats.get(sheetName); - if (rules == null && ! formats.containsKey(sheetName)) { + if (rules == null) { + if (formats.containsKey(sheetName)) { + return Collections.emptyList(); + } final SheetConditionalFormatting scf = sheet.getSheetConditionalFormatting(); final int count = scf.getNumConditionalFormattings(); rules = new ArrayList(count); @@ -149,12 +152,17 @@ public class ConditionalFormattingEvaluator { public List getConditionalFormattingForCell(final CellReference cellRef) { String sheetName = cellRef.getSheetName(); Sheet sheet = null; - if (sheetName == null) sheet = workbook.getSheetAt(workbook.getActiveSheetIndex()); - else sheet = workbook.getSheet(sheetName); + if (sheetName == null) { + sheet = workbook.getSheetAt(workbook.getActiveSheetIndex()); + } else { + sheet = workbook.getSheet(sheetName); + } final Cell cell = SheetUtil.getCell(sheet, cellRef.getRow(), cellRef.getCol()); - if (cell == null) return Collections.emptyList(); + if (cell == null) { + return Collections.emptyList(); + } return getConditionalFormattingForCell(cell, cellRef); } @@ -202,7 +210,9 @@ public class ConditionalFormattingEvaluator { boolean stopIfTrue = false; for (EvaluationConditionalFormatRule rule : getRules(cell.getSheet())) { - if (stopIfTrue) continue; // a previous rule matched and wants no more evaluations + if (stopIfTrue) { + continue; // a previous rule matched and wants no more evaluations + } if (rule.matches(cell)) { rules.add(rule); @@ -268,13 +278,19 @@ public class ConditionalFormattingEvaluator { for (CellRangeAddress region : rule.getRegions()) { for (int r = region.getFirstRow(); r <= region.getLastRow(); r++) { final Row row = sheet.getRow(r); - if (row == null) continue; // no cells to check + if (row == null) { + continue; // no cells to check + } for (int c = region.getFirstColumn(); c <= region.getLastColumn(); c++) { final Cell cell = row.getCell(c); - if (cell == null) continue; + if (cell == null) { + continue; + } List cellRules = getConditionalFormattingForCell(cell); - if (cellRules.contains(rule)) cells.add(cell); + if (cellRules.contains(rule)) { + cells.add(cell); + } } } } diff --git a/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java b/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java index b01a7fbf85..1bab3e9cae 100644 --- a/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java +++ b/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java @@ -185,9 +185,14 @@ public class EvaluationConditionalFormatRule implements Comparable evaluate(List allValues) { List values = allValues; final ConditionFilterData conf = rule.getFilterConfiguration(); - if (! conf.getBottom()) Collections.sort(values, Collections.reverseOrder()); - else Collections.sort(values); + if (! conf.getBottom()) { + Collections.sort(values, Collections.reverseOrder()); + } else { + Collections.sort(values); + } int limit = (int) conf.getRank(); - if (conf.getPercent()) limit = allValues.size() * limit / 100; - if (allValues.size() <= limit) return new HashSet(allValues); + if (conf.getPercent()) { + limit = allValues.size() * limit / 100; + } + if (allValues.size() <= limit) { + return new HashSet(allValues); + } return new HashSet(allValues.subList(0, limit)); } @@ -378,6 +412,7 @@ public class EvaluationConditionalFormatRule implements Comparable evaluate(List allValues) { List values = allValues; Collections.sort(values); @@ -402,6 +437,7 @@ public class EvaluationConditionalFormatRule implements Comparable evaluate(List allValues) { List values = allValues; Collections.sort(values); @@ -428,6 +464,7 @@ public class EvaluationConditionalFormatRule implements Comparable values = new ArrayList(getMeaningfulValues(region, false, new ValueFunction() { + @Override public Set evaluate(List allValues) { List values = allValues; double total = 0; @@ -449,7 +486,9 @@ public class EvaluationConditionalFormatRule implements Comparable getMeaningfulValues(CellRangeAddress region, boolean withText, ValueFunction func) { Set values = meaningfulRegionValues.get(region); - if (values != null) return values; + if (values != null) { + return values; + } List allValues = new ArrayList((region.getLastColumn() - region.getFirstColumn()+1) * (region.getLastRow() - region.getFirstRow() + 1)); for (int r=region.getFirstRow(); r <= region.getLastRow(); r++) { final Row row = sheet.getRow(r); - if (row == null) continue; + if (row == null) { + continue; + } for (int c = region.getFirstColumn(); c <= region.getLastColumn(); c++) { Cell cell = row.getCell(c); final ValueAndFormat cv = getCellValue(cell); - if (cv != null && (withText || cv.isNumber()) ) allValues.add(cv); + if (cv != null && (withText || cv.isNumber()) ) { + allValues.add(cv); + } } } @@ -578,21 +629,25 @@ public class EvaluationConditionalFormatRule implements Comparable> boolean isValid(C cellValue, C v1, C v2) { return false; } }, BETWEEN { + @Override public > boolean isValid(C cellValue, C v1, C v2) { return cellValue.compareTo(v1) >= 0 && cellValue.compareTo(v2) <= 0; } }, NOT_BETWEEN { + @Override public > boolean isValid(C cellValue, C v1, C v2) { return cellValue.compareTo(v1) < 0 || cellValue.compareTo(v2) > 0; } }, EQUAL { + @Override public > boolean isValid(C cellValue, C v1, C v2) { // need to avoid instanceof, to work around a 1.6 compiler bug if (cellValue.getClass() == String.class) { @@ -602,6 +657,7 @@ public class EvaluationConditionalFormatRule implements Comparable> boolean isValid(C cellValue, C v1, C v2) { // need to avoid instanceof, to work around a 1.6 compiler bug if (cellValue.getClass() == String.class) { @@ -611,21 +667,25 @@ public class EvaluationConditionalFormatRule implements Comparable> boolean isValid(C cellValue, C v1, C v2) { return cellValue.compareTo(v1) > 0; } }, LESS_THAN { + @Override public > boolean isValid(C cellValue, C v1, C v2) { return cellValue.compareTo(v1) < 0; } }, GREATER_OR_EQUAL { + @Override public > boolean isValid(C cellValue, C v1, C v2) { return cellValue.compareTo(v1) >= 0; } }, LESS_OR_EQUAL { + @Override public > boolean isValid(C cellValue, C v1, C v2) { return cellValue.compareTo(v1) <= 0; } @@ -645,7 +705,7 @@ public class EvaluationConditionalFormatRule implements Comparable { + protected static class ValueAndFormat implements Comparable { private final Double value; private final String string; @@ -671,7 +731,11 @@ public class EvaluationConditionalFormatRule implements Comparable { // check for emf+ embedded pdf (poor mans style :( ) // Mac Excel 2011 embeds pdf files with this method. PictureData pd = source.getPictureData(); - if (pd != null && pd.getPictureType() != Workbook.PICTURE_TYPE_EMF) { + if (pd == null || pd.getPictureType() != Workbook.PICTURE_TYPE_EMF) { return null; } diff --git a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBHyperlinksTable.java b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBHyperlinksTable.java index 049245f393..fd4eee0f15 100644 --- a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBHyperlinksTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBHyperlinksTable.java @@ -19,6 +19,7 @@ package org.apache.poi.xssf.binary; import java.io.IOException; import java.io.InputStream; +import java.io.Serializable; import java.util.ArrayList; import java.util.BitSet; import java.util.Comparator; @@ -163,8 +164,9 @@ public class XSSFBHyperlinksTable { } } - private static class TopLeftCellAddressComparator implements Comparator { - + private static class TopLeftCellAddressComparator implements Comparator, Serializable { + private static final long serialVersionUID = 1L; + @Override public int compare(CellAddress o1, CellAddress o2) { if (o1.getRow() < o2.getRow()) { diff --git a/src/scratchpad/src/org/apache/poi/hemf/record/HemfCommentPublic.java b/src/scratchpad/src/org/apache/poi/hemf/record/HemfCommentPublic.java index cb0447619a..87f282d653 100644 --- a/src/scratchpad/src/org/apache/poi/hemf/record/HemfCommentPublic.java +++ b/src/scratchpad/src/org/apache/poi/hemf/record/HemfCommentPublic.java @@ -25,6 +25,7 @@ import java.util.List; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.RecordFormatException; /** @@ -71,11 +72,11 @@ public class HemfCommentPublic { //note that raw bytes includes the public comment identifier int currentOffset = 4 + 16;//4 public comment identifier, 16 for outputrect long countFormats = LittleEndian.getUInt(rawBytes, currentOffset); - currentOffset += LittleEndian.INT_SIZE; + currentOffset += LittleEndianConsts.INT_SIZE; List emrFormatList = new ArrayList(); for (long i = 0; i < countFormats; i++) { emrFormatList.add(new EmrFormat(rawBytes, currentOffset)); - currentOffset += 4 * LittleEndian.INT_SIZE; + currentOffset += 4 * LittleEndianConsts.INT_SIZE; } List list = new ArrayList(); for (EmrFormat emrFormat : emrFormatList) { @@ -86,20 +87,20 @@ public class HemfCommentPublic { return list; } - private class EmrFormat { + private static class EmrFormat { long signature; long version; int size; int offset; public EmrFormat(byte[] rawBytes, int currentOffset) { - signature = LittleEndian.getUInt(rawBytes, currentOffset); currentOffset += LittleEndian.INT_SIZE; - version = LittleEndian.getUInt(rawBytes, currentOffset); currentOffset += LittleEndian.INT_SIZE; + signature = LittleEndian.getUInt(rawBytes, currentOffset); currentOffset += LittleEndianConsts.INT_SIZE; + version = LittleEndian.getUInt(rawBytes, currentOffset); currentOffset += LittleEndianConsts.INT_SIZE; //spec says this must be a 32bit "aligned" typo for "signed"? //realistically, this has to be an int... - size = LittleEndian.getInt(rawBytes, currentOffset); currentOffset += LittleEndian.INT_SIZE; + size = LittleEndian.getInt(rawBytes, currentOffset); currentOffset += LittleEndianConsts.INT_SIZE; //y, can be long, but realistically? - offset = LittleEndian.getInt(rawBytes, currentOffset); currentOffset += LittleEndian.INT_SIZE; + offset = LittleEndian.getInt(rawBytes, currentOffset); currentOffset += LittleEndianConsts.INT_SIZE; if (size < 0) { throw new RecordFormatException("size for emrformat must be > 0"); } @@ -118,12 +119,12 @@ public class HemfCommentPublic { private final byte[] wmfBytes; public WindowsMetafile(byte[] rawBytes) { super(rawBytes); - int offset = LittleEndian.INT_SIZE;//public comment identifier - int version = LittleEndian.getUShort(rawBytes, offset); offset += LittleEndian.SHORT_SIZE; - int reserved = LittleEndian.getUShort(rawBytes, offset); offset += LittleEndian.SHORT_SIZE; - offset += LittleEndian.INT_SIZE; //checksum - offset += LittleEndian.INT_SIZE; //flags - long winMetafileSizeLong = LittleEndian.getUInt(rawBytes, offset); offset += LittleEndian.INT_SIZE; + int offset = LittleEndianConsts.INT_SIZE;//public comment identifier + int version = LittleEndian.getUShort(rawBytes, offset); offset += LittleEndianConsts.SHORT_SIZE; + int reserved = LittleEndian.getUShort(rawBytes, offset); offset += LittleEndianConsts.SHORT_SIZE; + offset += LittleEndianConsts.INT_SIZE; //checksum + offset += LittleEndianConsts.INT_SIZE; //flags + long winMetafileSizeLong = LittleEndian.getUInt(rawBytes, offset); offset += LittleEndianConsts.INT_SIZE; if (winMetafileSizeLong == 0L) { wmfBytes = new byte[0]; return;