From: Andreas Beeker Date: Sun, 12 Jun 2016 00:12:22 +0000 (+0000) Subject: findbugs fixes X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=81d891921b14133312dd4a62b3b0f105b66b73c1;p=poi.git findbugs fixes changed UDFFinder to abstract class and moved DEFAULT constant to factory method git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1747942 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/examples/src/org/apache/poi/ss/examples/formula/SettingExternalFunction.java b/src/examples/src/org/apache/poi/ss/examples/formula/SettingExternalFunction.java index ae70794368..df79f5a354 100644 --- a/src/examples/src/org/apache/poi/ss/examples/formula/SettingExternalFunction.java +++ b/src/examples/src/org/apache/poi/ss/examples/formula/SettingExternalFunction.java @@ -48,7 +48,7 @@ public class SettingExternalFunction { /** * wrap external functions in a plugin */ - public static class BloombergAddIn implements UDFFinder { + public static class BloombergAddIn extends UDFFinder { private final Map _functionsByName; public BloombergAddIn() { @@ -89,6 +89,7 @@ public class SettingExternalFunction { wb.write(out); out.close(); + wb.close(); } } diff --git a/src/java/org/apache/poi/ddf/EscherArrayProperty.java b/src/java/org/apache/poi/ddf/EscherArrayProperty.java index ed3bd32989..bf7211d3c0 100644 --- a/src/java/org/apache/poi/ddf/EscherArrayProperty.java +++ b/src/java/org/apache/poi/ddf/EscherArrayProperty.java @@ -165,7 +165,7 @@ public final class EscherArrayProperty extends EscherComplexProperty implements _complexData = new byte[0]; } else { short numElements = LittleEndian.getShort(data, offset); - LittleEndian.getShort(data, offset + 2); // numReserved + // LittleEndian.getShort(data, offset + 2); // numReserved short sizeOfElements = LittleEndian.getShort(data, offset + 4); int arraySize = getActualSizeOfElements(sizeOfElements) * numElements; diff --git a/src/java/org/apache/poi/ddf/EscherColorRef.java b/src/java/org/apache/poi/ddf/EscherColorRef.java index d48c5de256..84f94301d3 100644 --- a/src/java/org/apache/poi/ddf/EscherColorRef.java +++ b/src/java/org/apache/poi/ddf/EscherColorRef.java @@ -181,7 +181,7 @@ public class EscherColorRef { } public void setSysIndexFlag(boolean flag) { - FLAG_SYS_INDEX.setBoolean(colorRef, flag); + colorRef = FLAG_SYS_INDEX.setBoolean(colorRef, flag); } public boolean hasSchemeIndexFlag() { @@ -189,7 +189,7 @@ public class EscherColorRef { } public void setSchemeIndexFlag(boolean flag) { - FLAG_SCHEME_INDEX.setBoolean(colorRef, flag); + colorRef = FLAG_SCHEME_INDEX.setBoolean(colorRef, flag); } public boolean hasSystemRGBFlag() { @@ -197,7 +197,7 @@ public class EscherColorRef { } public void setSystemRGBFlag(boolean flag) { - FLAG_SYSTEM_RGB.setBoolean(colorRef, flag); + colorRef = FLAG_SYSTEM_RGB.setBoolean(colorRef, flag); } public boolean hasPaletteRGBFlag() { @@ -205,7 +205,7 @@ public class EscherColorRef { } public void setPaletteRGBFlag(boolean flag) { - FLAG_PALETTE_RGB.setBoolean(colorRef, flag); + colorRef = FLAG_PALETTE_RGB.setBoolean(colorRef, flag); } public boolean hasPaletteIndexFlag() { @@ -213,7 +213,7 @@ public class EscherColorRef { } public void setPaletteIndexFlag(boolean flag) { - FLAG_PALETTE_INDEX.setBoolean(colorRef, flag); + colorRef = FLAG_PALETTE_INDEX.setBoolean(colorRef, flag); } public int[] getRGB() { diff --git a/src/java/org/apache/poi/ddf/EscherDggRecord.java b/src/java/org/apache/poi/ddf/EscherDggRecord.java index dcf5e7d211..5b1b8b744a 100644 --- a/src/java/org/apache/poi/ddf/EscherDggRecord.java +++ b/src/java/org/apache/poi/ddf/EscherDggRecord.java @@ -70,7 +70,8 @@ public final class EscherDggRecord extends EscherRecord { int pos = offset + 8; int size = 0; field_1_shapeIdMax = LittleEndian.getInt( data, pos + size );size+=4; - LittleEndian.getInt( data, pos + size );size+=4; // field_2_numIdClusters + // field_2_numIdClusters = LittleEndian.getInt( data, pos + size ); + size+=4; field_3_numShapesSaved = LittleEndian.getInt( data, pos + size );size+=4; field_4_drawingsSaved = LittleEndian.getInt( data, pos + size );size+=4; field_5_fileIdClusters = new FileIdCluster[(bytesRemaining-size) / 8]; // Can't rely on field_2_numIdClusters diff --git a/src/java/org/apache/poi/hpsf/VariantBool.java b/src/java/org/apache/poi/hpsf/VariantBool.java index 667b1047d9..962674de71 100644 --- a/src/java/org/apache/poi/hpsf/VariantBool.java +++ b/src/java/org/apache/poi/hpsf/VariantBool.java @@ -22,42 +22,34 @@ import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @Internal -class VariantBool -{ - private final static POILogger logger = POILogFactory - .getLogger( VariantBool.class ); +class VariantBool { + private final static POILogger logger = POILogFactory.getLogger( VariantBool.class ); static final int SIZE = 2; private boolean _value; - VariantBool( byte[] data, int offset ) - { + VariantBool( byte[] data, int offset ) { short value = LittleEndian.getShort( data, offset ); - if ( value == 0x0000 ) - { - _value = false; - return; + switch (value) { + case 0: + _value = false; + break; + case -1: + _value = true; + break; + default: + logger.log( POILogger.WARN, "VARIANT_BOOL value '"+value+"' is incorrect" ); + _value = true; + break; } - - if ( value == 0xffff ) - { - _value = true; - return; - } - - logger.log( POILogger.WARN, "VARIANT_BOOL value '", - Short.valueOf( value ), "' is incorrect" ); - _value = value != 0; } - boolean getValue() - { + boolean getValue() { return _value; } - void setValue( boolean value ) - { + void setValue( boolean value ) { this._value = value; } } diff --git a/src/java/org/apache/poi/hssf/record/common/FeatFormulaErr2.java b/src/java/org/apache/poi/hssf/record/common/FeatFormulaErr2.java index 866c311fcf..8ab9936320 100644 --- a/src/java/org/apache/poi/hssf/record/common/FeatFormulaErr2.java +++ b/src/java/org/apache/poi/hssf/record/common/FeatFormulaErr2.java @@ -36,22 +36,14 @@ import org.apache.poi.util.LittleEndianOutput; * https://msdn.microsoft.com/en-us/library/dd924991%28v=office.12%29.aspx */ public final class FeatFormulaErr2 implements SharedFeature { - static BitField checkCalculationErrors = - BitFieldFactory.getInstance(0x01); - static BitField checkEmptyCellRef = - BitFieldFactory.getInstance(0x02); - static BitField checkNumbersAsText = - BitFieldFactory.getInstance(0x04); - static BitField checkInconsistentRanges = - BitFieldFactory.getInstance(0x08); - static BitField checkInconsistentFormulas = - BitFieldFactory.getInstance(0x10); - static BitField checkDateTimeFormats = - BitFieldFactory.getInstance(0x20); - static BitField checkUnprotectedFormulas = - BitFieldFactory.getInstance(0x40); - static BitField performDataValidation = - BitFieldFactory.getInstance(0x80); + private static final BitField CHECK_CALCULATION_ERRORS = BitFieldFactory.getInstance(0x01); + private static final BitField CHECK_EMPTY_CELL_REF = BitFieldFactory.getInstance(0x02); + private static final BitField CHECK_NUMBERS_AS_TEXT = BitFieldFactory.getInstance(0x04); + private static final BitField CHECK_INCONSISTENT_RANGES = BitFieldFactory.getInstance(0x08); + private static final BitField CHECK_INCONSISTENT_FORMULAS = BitFieldFactory.getInstance(0x10); + private static final BitField CHECK_DATETIME_FORMATS = BitFieldFactory.getInstance(0x20); + private static final BitField CHECK_UNPROTECTED_FORMULAS = BitFieldFactory.getInstance(0x40); + private static final BitField PERFORM_DATA_VALIDATION = BitFieldFactory.getInstance(0x80); /** * What errors we should ignore @@ -93,67 +85,58 @@ public final class FeatFormulaErr2 implements SharedFeature { } public boolean getCheckCalculationErrors() { - return checkCalculationErrors.isSet(errorCheck); + return CHECK_CALCULATION_ERRORS.isSet(errorCheck); } public void setCheckCalculationErrors(boolean checkCalculationErrors) { - FeatFormulaErr2.checkCalculationErrors.setBoolean( - errorCheck, checkCalculationErrors); + errorCheck = CHECK_CALCULATION_ERRORS.setBoolean(errorCheck, checkCalculationErrors); } public boolean getCheckEmptyCellRef() { - return checkEmptyCellRef.isSet(errorCheck); + return CHECK_EMPTY_CELL_REF.isSet(errorCheck); } public void setCheckEmptyCellRef(boolean checkEmptyCellRef) { - FeatFormulaErr2.checkEmptyCellRef.setBoolean( - errorCheck, checkEmptyCellRef); + errorCheck = CHECK_EMPTY_CELL_REF.setBoolean(errorCheck, checkEmptyCellRef); } public boolean getCheckNumbersAsText() { - return checkNumbersAsText.isSet(errorCheck); + return CHECK_NUMBERS_AS_TEXT.isSet(errorCheck); } public void setCheckNumbersAsText(boolean checkNumbersAsText) { - FeatFormulaErr2.checkNumbersAsText.setBoolean( - errorCheck, checkNumbersAsText); + errorCheck = CHECK_NUMBERS_AS_TEXT.setBoolean(errorCheck, checkNumbersAsText); } public boolean getCheckInconsistentRanges() { - return checkInconsistentRanges.isSet(errorCheck); + return CHECK_INCONSISTENT_RANGES.isSet(errorCheck); } public void setCheckInconsistentRanges(boolean checkInconsistentRanges) { - FeatFormulaErr2.checkInconsistentRanges.setBoolean( - errorCheck, checkInconsistentRanges); + errorCheck = CHECK_INCONSISTENT_RANGES.setBoolean(errorCheck, checkInconsistentRanges); } public boolean getCheckInconsistentFormulas() { - return checkInconsistentFormulas.isSet(errorCheck); + return CHECK_INCONSISTENT_FORMULAS.isSet(errorCheck); } - public void setCheckInconsistentFormulas( - boolean checkInconsistentFormulas) { - FeatFormulaErr2.checkInconsistentFormulas.setBoolean( - errorCheck, checkInconsistentFormulas); + public void setCheckInconsistentFormulas(boolean checkInconsistentFormulas) { + errorCheck = CHECK_INCONSISTENT_FORMULAS.setBoolean(errorCheck, checkInconsistentFormulas); } public boolean getCheckDateTimeFormats() { - return checkDateTimeFormats.isSet(errorCheck); + return CHECK_DATETIME_FORMATS.isSet(errorCheck); } public void setCheckDateTimeFormats(boolean checkDateTimeFormats) { - FeatFormulaErr2.checkDateTimeFormats.setBoolean( - errorCheck, checkDateTimeFormats); + errorCheck = CHECK_DATETIME_FORMATS.setBoolean(errorCheck, checkDateTimeFormats); } public boolean getCheckUnprotectedFormulas() { - return checkUnprotectedFormulas.isSet(errorCheck); + return CHECK_UNPROTECTED_FORMULAS.isSet(errorCheck); } public void setCheckUnprotectedFormulas(boolean checkUnprotectedFormulas) { - FeatFormulaErr2.checkUnprotectedFormulas.setBoolean( - errorCheck, checkUnprotectedFormulas); + errorCheck = CHECK_UNPROTECTED_FORMULAS.setBoolean(errorCheck, checkUnprotectedFormulas); } public boolean getPerformDataValidation() { - return performDataValidation.isSet(errorCheck); + return PERFORM_DATA_VALIDATION.isSet(errorCheck); } public void setPerformDataValidation(boolean performDataValidation) { - FeatFormulaErr2.performDataValidation.setBoolean( - errorCheck, performDataValidation); + errorCheck = PERFORM_DATA_VALIDATION.setBoolean(errorCheck, performDataValidation); } } diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index c10e4edae1..32d2a5fd8b 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -181,7 +181,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss * The locator of user-defined functions. * By default includes functions from the Excel Analysis Toolpack */ - private UDFFinder _udfFinder = new IndexedUDFFinder(UDFFinder.DEFAULT); + private UDFFinder _udfFinder = new IndexedUDFFinder(UDFFinder.getDefault()); public static HSSFWorkbook create(InternalWorkbook book) { return new HSSFWorkbook(book); diff --git a/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java b/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java index a0da336d77..106709cea8 100644 --- a/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java +++ b/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java @@ -44,7 +44,7 @@ import org.apache.poi.ss.formula.udf.UDFFinder; /** * Analysis Toolpack Function Definitions */ -public final class AnalysisToolPak implements UDFFinder { +public final class AnalysisToolPak extends UDFFinder { public static final UDFFinder instance = new AnalysisToolPak(); diff --git a/src/java/org/apache/poi/ss/formula/udf/AggregatingUDFFinder.java b/src/java/org/apache/poi/ss/formula/udf/AggregatingUDFFinder.java index ce47aeb82b..7d19de33cb 100644 --- a/src/java/org/apache/poi/ss/formula/udf/AggregatingUDFFinder.java +++ b/src/java/org/apache/poi/ss/formula/udf/AggregatingUDFFinder.java @@ -25,10 +25,8 @@ import java.util.Collection; /** * Collects add-in libraries and VB macro functions together into one UDF finder - * - * @author PUdalau */ -public class AggregatingUDFFinder implements UDFFinder { +public class AggregatingUDFFinder extends UDFFinder { private final Collection _usedToolPacks; diff --git a/src/java/org/apache/poi/ss/formula/udf/DefaultUDFFinder.java b/src/java/org/apache/poi/ss/formula/udf/DefaultUDFFinder.java index 382820b1ef..71e709b842 100644 --- a/src/java/org/apache/poi/ss/formula/udf/DefaultUDFFinder.java +++ b/src/java/org/apache/poi/ss/formula/udf/DefaultUDFFinder.java @@ -25,10 +25,8 @@ import org.apache.poi.ss.formula.functions.FreeRefFunction; /** * Default UDF finder - for adding your own user defined functions. - * - * @author PUdalau */ -public final class DefaultUDFFinder implements UDFFinder { +public final class DefaultUDFFinder extends UDFFinder { private final Map _functionsByName; public DefaultUDFFinder(String[] functionNames, FreeRefFunction[] functionImpls) { diff --git a/src/java/org/apache/poi/ss/formula/udf/UDFFinder.java b/src/java/org/apache/poi/ss/formula/udf/UDFFinder.java index d611f94e9a..46d754540e 100644 --- a/src/java/org/apache/poi/ss/formula/udf/UDFFinder.java +++ b/src/java/org/apache/poi/ss/formula/udf/UDFFinder.java @@ -22,12 +22,11 @@ import org.apache.poi.ss.formula.functions.FreeRefFunction; /** * Common interface for "Add-in" libraries and user defined function libraries. - * - * @author PUdalau */ -public interface UDFFinder { - // FIXME: Findbugs error: IC_SUPERCLASS_USES_SUBCLASS_DURING_INITIALIZATION - public static final UDFFinder DEFAULT = new AggregatingUDFFinder(AnalysisToolPak.instance); +public abstract class UDFFinder { + public static UDFFinder getDefault() { + return new AggregatingUDFFinder(AnalysisToolPak.instance); + } /** * Returns executor by specified name. Returns null if the function name is unknown. @@ -35,5 +34,5 @@ public interface UDFFinder { * @param name Name of function. * @return Function executor. */ - FreeRefFunction findFunction(String name); + public abstract FreeRefFunction findFunction(String name); } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java index 1772fad1c2..5d83e9f223 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java @@ -769,7 +769,7 @@ public final class PackagingURIHelper { }; private static boolean isUnsafe(int ch) { - return ch > 0x80 || Character.isWhitespace(ch) || ch == '\u00A0'; + return ch > 0x80 || Character.isWhitespace(ch); } } diff --git a/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFRelation.java b/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFRelation.java index 1733754874..3ab1f91d3b 100644 --- a/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFRelation.java +++ b/src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFRelation.java @@ -29,7 +29,7 @@ public class XDGFRelation extends POIXMLRelation { /** * A map to lookup POIXMLRelation by its relation type */ - protected static final Map _table = new HashMap(); + private static final Map _table = new HashMap(); public static final XDGFRelation DOCUMENT = new XDGFRelation( "application/vnd.ms-visio.drawing.main+xml", diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java index 5ea703ee69..f3f59b918a 100644 --- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java +++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java @@ -30,7 +30,7 @@ public class XSLFRelation extends POIXMLRelation { /** * A map to lookup POIXMLRelation by its relation type */ - protected static final Map _table = new HashMap(); + private static final Map _table = new HashMap(); public static final XSLFRelation MAIN = new XSLFRelation( "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml", diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java index ac2f835676..9a16f00dc7 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java @@ -54,7 +54,7 @@ public final class XSSFRelation extends POIXMLRelation { /** * A map to lookup POIXMLRelation by its relation type */ - protected static final Map _table = new HashMap(); + private static final Map _table = new HashMap(); public static final XSSFRelation WORKBOOK = new XSSFRelation( diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java index 13b15bf28c..5c8b385b76 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java @@ -72,7 +72,7 @@ public class XSSFRow implements Row, Comparable { _cells = new TreeMap(); for (CTCell c : row.getCArray()) { XSSFCell cell = new XSSFCell(this, c); - _cells.put(new Integer(cell.getColumnIndex()), cell); + _cells.put(cell.getColumnIndex(), cell); sheet.onReadCell(cell); } } @@ -198,7 +198,7 @@ public class XSSFRow implements Row, Comparable { */ public XSSFCell createCell(int columnIndex, int type) { CTCell ctCell; - XSSFCell prev = _cells.get(new Integer(columnIndex)); + XSSFCell prev = _cells.get(columnIndex); if(prev != null){ ctCell = prev.getCTCell(); ctCell.set(CTCell.Factory.newInstance()); @@ -210,7 +210,7 @@ public class XSSFRow implements Row, Comparable { if (type != Cell.CELL_TYPE_BLANK) { xcell.setCellType(type); } - _cells.put(new Integer(columnIndex), xcell); + _cells.put(columnIndex, xcell); return xcell; } @@ -236,7 +236,7 @@ public class XSSFRow implements Row, Comparable { public XSSFCell getCell(int cellnum, MissingCellPolicy policy) { if(cellnum < 0) throw new IllegalArgumentException("Cell index must be >= 0"); - XSSFCell cell = _cells.get(new Integer(cellnum)); + XSSFCell cell = _cells.get(cellnum); if(policy == RETURN_NULL_AND_BLANK) { return cell; } @@ -455,7 +455,7 @@ public class XSSFRow implements Row, Comparable { if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) { _sheet.getWorkbook().onDeleteFormula(xcell); } - _cells.remove(new Integer(cell.getColumnIndex())); + _cells.remove(cell.getColumnIndex()); } /** diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 742720f788..74a861b414 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -160,7 +160,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { * The locator of user-defined functions. * By default includes functions from the Excel Analysis Toolpack */ - private IndexedUDFFinder _udfFinder = new IndexedUDFFinder(UDFFinder.DEFAULT); + private IndexedUDFFinder _udfFinder = new IndexedUDFFinder(UDFFinder.getDefault()); /** * TODO diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java index 59b97c3a45..0afaedc718 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java @@ -31,7 +31,7 @@ public final class XWPFRelation extends POIXMLRelation { /** * A map to lookup POIXMLRelation by its relation type */ - protected static final Map _table = new HashMap(); + private static final Map _table = new HashMap(); public static final XWPFRelation DOCUMENT = new XWPFRelation( "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java index d975e73094..a8847d0726 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java @@ -91,15 +91,18 @@ public abstract class BitMaskTextProp extends TextProp implements Cloneable { */ @Override public int getValue() { - int val = dataValue, i = 0; - for (int mask : subPropMasks) { - if (!subPropMatches[i++]) { - val &= ~mask; - } - } - return val; + return maskValue(dataValue); + } + + private int maskValue(int pVal) { + int val = pVal, i = 0; + for (int mask : subPropMasks) { + if (!subPropMatches[i++]) { + val &= ~mask; + } + } + return val; } - /** * Set the value of the text property, and recompute the sub @@ -125,8 +128,7 @@ public abstract class BitMaskTextProp extends TextProp implements Cloneable { */ public void setValueWithMask(int val, int writeMask) { setWriteMask(writeMask); - dataValue = val; - dataValue = getValue(); + dataValue = maskValue(val); if (val != dataValue) { logger.log(POILogger.WARN, "Style properties of '"+getName()+"' don't match mask - output will be sanitized"); if (logger.check(POILogger.DEBUG)) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java index b828886c95..8ca4678a29 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java @@ -381,6 +381,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape getShadow() { AbstractEscherOptRecord opt = getEscherOptRecord(); + if (opt == null) return null; EscherProperty shadowType = opt.lookup(EscherProperties.SHADOWSTYLE__TYPE); if (shadowType == null) return null; diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java index 750c74ebf3..a1e76d560a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java @@ -424,7 +424,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { // If they type (including the bonus 0xF018) is 0, skip it PictureType pt = PictureType.forNativeID(type - 0xF018); - if(type == 0 || pt == null) { + if (pt == null) { logger.log(POILogger.ERROR, "Problem reading picture: Invalid image type 0, on picture with length " + imgsize + ".\nYou document will probably become corrupted if you save it!"); logger.log(POILogger.ERROR, "" + pos); } else { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java index a61db1bd24..3cbd3f085a 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java @@ -133,7 +133,7 @@ public final class BorderCode implements Cloneable { } public void setBorderType(int borderType) { - _brcType.setValue(_info, borderType); + _info = (short)_brcType.setValue(_info, borderType); } /** @@ -161,7 +161,7 @@ public final class BorderCode implements Cloneable { } public void setColor(short color) { - _ico.setValue(_info2, color); + _info2 = (short)_ico.setValue(_info2, color); } /** @@ -176,7 +176,7 @@ public final class BorderCode implements Cloneable { } public void setSpace(int space) { - _dptSpace.setValue(_info2, space); + _info2 = (short)_dptSpace.setValue(_info2, space); } /** @@ -188,7 +188,7 @@ public final class BorderCode implements Cloneable { } public void setShadow(boolean shadow) { - _fShadow.setValue(_info2, shadow ? 1 : 0); + _info2 = (short)_fShadow.setValue(_info2, shadow ? 1 : 0); } /** @@ -199,7 +199,7 @@ public final class BorderCode implements Cloneable { } public void setFrame(boolean frame) { - _fFrame.setValue(_info2, frame ? 1 : 0); + _info2 = (short)_fFrame.setValue(_info2, frame ? 1 : 0); } @Override diff --git a/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java b/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java index 14b4fbfc1d..726c4e86fa 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/model/TestWorkbook.java @@ -17,28 +17,36 @@ package org.apache.poi.hssf.model; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; import org.apache.poi.hssf.record.CountryRecord; import org.apache.poi.hssf.record.FontRecord; import org.apache.poi.hssf.record.RecalcIdRecord; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.TestHSSFWorkbook; -import org.apache.poi.ss.formula.udf.UDFFinder; -import org.apache.poi.ss.formula.udf.DefaultUDFFinder; -import org.apache.poi.ss.formula.udf.AggregatingUDFFinder; -import org.apache.poi.ss.formula.functions.FreeRefFunction; -import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.formula.OperationEvaluationContext; +import org.apache.poi.ss.formula.eval.ValueEval; +import org.apache.poi.ss.formula.functions.FreeRefFunction; +import org.apache.poi.ss.formula.udf.AggregatingUDFFinder; +import org.apache.poi.ss.formula.udf.DefaultUDFFinder; +import org.apache.poi.ss.formula.udf.UDFFinder; +import org.junit.Test; /** * Unit test for the Workbook class. - * - * @author Glen Stampoultzis (glens at apache.org) */ -public final class TestWorkbook extends TestCase { - public void testFontStuff() { - InternalWorkbook wb = TestHSSFWorkbook.getInternalWorkbook(new HSSFWorkbook()); +public final class TestWorkbook { + @Test + public void testFontStuff() throws IOException { + HSSFWorkbook hwb = new HSSFWorkbook(); + InternalWorkbook wb = TestHSSFWorkbook.getInternalWorkbook(hwb); assertEquals(4, wb.getNumberOfFontRecords()); assertEquals(68, wb.getRecords().size()); @@ -90,11 +98,15 @@ public final class TestWorkbook extends TestCase { assertEquals(6, wb.getNumberOfFontRecords()); assertEquals(6, wb.getFontIndex(n7)); assertEquals(n7, wb.getFontRecordAt(6)); + + hwb.close(); } - public void testAddNameX(){ - InternalWorkbook wb = TestHSSFWorkbook.getInternalWorkbook(new HSSFWorkbook()); - assertNotNull(wb.getNameXPtg("ISODD", UDFFinder.DEFAULT)); + @Test + public void testAddNameX() throws IOException { + HSSFWorkbook hwb = new HSSFWorkbook(); + InternalWorkbook wb = TestHSSFWorkbook.getInternalWorkbook(hwb); + assertNotNull(wb.getNameXPtg("ISODD", UDFFinder.getDefault())); FreeRefFunction NotImplemented = new FreeRefFunction() { public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) { @@ -114,9 +126,12 @@ public final class TestWorkbook extends TestCase { assertNotNull(wb.getNameXPtg("myFunc2", udff)); assertNull(wb.getNameXPtg("myFunc3", udff)); // myFunc3 is unknown + + hwb.close(); } - public void testRecalcId(){ + @Test + public void testRecalcId() throws IOException { HSSFWorkbook wb = new HSSFWorkbook(); assertFalse(wb.getForceFormulaRecalculation()); @@ -139,5 +154,7 @@ public final class TestWorkbook extends TestCase { wb.setForceFormulaRecalculation(true); // resets the EngineId flag to zero assertEquals(0, record.getEngineId()); assertFalse(wb.getForceFormulaRecalculation()); + + wb.close(); } } diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java index 705e4ae91d..95d173aa3e 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java +++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java @@ -38,6 +38,7 @@ import org.apache.poi.ss.format.CellFormat; import org.apache.poi.ss.format.CellFormatResult; import org.apache.poi.ss.util.NumberToTextConverter; import org.apache.poi.util.LocaleUtil; +import org.apache.poi.util.SuppressForbidden; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -52,13 +53,15 @@ public class TestDataFormatter { private static final double _15_MINUTES = 0.041666667; @BeforeClass + @SuppressForbidden public static void setUpClass() { // some pre-checks to hunt for a problem in the Maven build // these checks ensure that the correct locale is set, so a failure here // usually indicates an invalid locale during test-execution assertFalse(DateUtil.isADateFormat(-1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-")); - assertEquals(Locale.getDefault(), LocaleUtil.getUserLocale()); + Locale ul = LocaleUtil.getUserLocale(); + assertTrue(Locale.ROOT.equals(ul) || Locale.getDefault().equals(ul)); final String textValue = NumberToTextConverter.toText(1234.56); assertEquals(-1, textValue.indexOf('E')); Object cellValueO = Double.valueOf(1234.56);