]> source.dussan.org Git - poi.git/commitdiff
findbugs fixes
authorAndreas Beeker <kiwiwings@apache.org>
Sun, 12 Jun 2016 00:12:22 +0000 (00:12 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Sun, 12 Jun 2016 00:12:22 +0000 (00:12 +0000)
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

24 files changed:
src/examples/src/org/apache/poi/ss/examples/formula/SettingExternalFunction.java
src/java/org/apache/poi/ddf/EscherArrayProperty.java
src/java/org/apache/poi/ddf/EscherColorRef.java
src/java/org/apache/poi/ddf/EscherDggRecord.java
src/java/org/apache/poi/hpsf/VariantBool.java
src/java/org/apache/poi/hssf/record/common/FeatFormulaErr2.java
src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java
src/java/org/apache/poi/ss/formula/udf/AggregatingUDFFinder.java
src/java/org/apache/poi/ss/formula/udf/DefaultUDFFinder.java
src/java/org/apache/poi/ss/formula/udf/UDFFinder.java
src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java
src/ooxml/java/org/apache/poi/xdgf/usermodel/XDGFRelation.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFRelation.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRelation.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java
src/scratchpad/src/org/apache/poi/hslf/model/textproperties/BitMaskTextProp.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSimpleShape.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java
src/scratchpad/src/org/apache/poi/hwpf/usermodel/BorderCode.java
src/testcases/org/apache/poi/hssf/model/TestWorkbook.java
src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java

index ae7079436876b00c7e9ef572f82ca710391f5605..df79f5a354f823ed8c221ad850dc4d90118a7c52 100644 (file)
@@ -48,7 +48,7 @@ public class SettingExternalFunction {
     /**\r
      * wrap external functions in a plugin\r
      */\r
-    public static class BloombergAddIn implements UDFFinder {\r
+    public static class BloombergAddIn extends UDFFinder {\r
         private final Map<String, FreeRefFunction> _functionsByName;\r
 \r
         public BloombergAddIn() {\r
@@ -89,6 +89,7 @@ public class SettingExternalFunction {
         wb.write(out);\r
         out.close();\r
 \r
+        wb.close();\r
     }\r
 \r
 }\r
index ed3bd329890be853dd6db177a62fb6e4a56fd6be..bf7211d3c0f04407465f6eb3107c92ed955cedfc 100644 (file)
@@ -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;
index d48c5de25646ce244a19824c0764c6df15035baa..84f94301d33d0d7d05f29654b52736f24b867ae5 100644 (file)
@@ -181,7 +181,7 @@ public class EscherColorRef {
     }\r
     \r
     public void setSysIndexFlag(boolean flag) {\r
-        FLAG_SYS_INDEX.setBoolean(colorRef, flag);\r
+        colorRef = FLAG_SYS_INDEX.setBoolean(colorRef, flag);\r
     }\r
     \r
     public boolean hasSchemeIndexFlag() {\r
@@ -189,7 +189,7 @@ public class EscherColorRef {
     }\r
     \r
     public void setSchemeIndexFlag(boolean flag) {\r
-        FLAG_SCHEME_INDEX.setBoolean(colorRef, flag);\r
+        colorRef = FLAG_SCHEME_INDEX.setBoolean(colorRef, flag);\r
     }\r
     \r
     public boolean hasSystemRGBFlag() {\r
@@ -197,7 +197,7 @@ public class EscherColorRef {
     }\r
     \r
     public void setSystemRGBFlag(boolean flag) {\r
-        FLAG_SYSTEM_RGB.setBoolean(colorRef, flag);\r
+        colorRef = FLAG_SYSTEM_RGB.setBoolean(colorRef, flag);\r
     }\r
     \r
     public boolean hasPaletteRGBFlag() {\r
@@ -205,7 +205,7 @@ public class EscherColorRef {
     }\r
     \r
     public void setPaletteRGBFlag(boolean flag) {\r
-        FLAG_PALETTE_RGB.setBoolean(colorRef, flag);\r
+        colorRef = FLAG_PALETTE_RGB.setBoolean(colorRef, flag);\r
     }\r
     \r
     public boolean hasPaletteIndexFlag() {\r
@@ -213,7 +213,7 @@ public class EscherColorRef {
     }\r
     \r
     public void setPaletteIndexFlag(boolean flag) {\r
-        FLAG_PALETTE_INDEX.setBoolean(colorRef, flag);\r
+        colorRef = FLAG_PALETTE_INDEX.setBoolean(colorRef, flag);\r
     }\r
 \r
     public int[] getRGB() {\r
index dcf5e7d211f5367cd2a603f335134233f38cc5e2..5b1b8b744ae24419861af0c319fde866806bcae7 100644 (file)
@@ -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
index 667b1047d923b89386147cab3b04be85ae201a5f..962674de71673a8c61f5fcfa4ac35bd612a49cfc 100644 (file)
@@ -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;
     }
 }
index 866c311fcf441bf14928c2debe7cc9952bced16c..8ab9936320ac61c299a9f7376af338d552d60142 100644 (file)
@@ -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);
        }
 }
index c10e4edae1c850a2f0580512ca5f4312a81ea3aa..32d2a5fd8b2112e225f19f9833227f7b05f6273e 100644 (file)
@@ -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);
index a0da336d77c547034b85a8f6e601f7bec98e4048..106709cea86ea3efd28f88b3c86dcc6b12554719 100644 (file)
@@ -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();
 
index ce47aeb82ba82b83d2efa9a0f0dc737a666e7883..7d19de33cb0e113278a247473a14714b8ab9ff70 100644 (file)
@@ -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<UDFFinder> _usedToolPacks;
 
index 382820b1efeb2f33c21104251c7457e6e26e89b3..71e709b842f8fe68ef5c692e961265fbd4bb21f7 100644 (file)
@@ -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<String, FreeRefFunction> _functionsByName;
 
     public DefaultUDFFinder(String[] functionNames, FreeRefFunction[] functionImpls) {
index d611f94e9ae9b8b6ed7973b628042cbb5db0861f..46d754540ee333ae79ecf1b09a9fd200723e2d7d 100644 (file)
@@ -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 <code>null</code> 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);
 }
index 1772fad1c263a72fa1a65fad8132f6b9a2f557e3..5d83e9f223f02d960d200ba74346f73cc415e916 100644 (file)
@@ -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);
     }
 
 }
index 17337548747fa826786e284fb4d5e31f74ba34a6..3ab1f91d3b64cfd9e63ea42f7ff47c7bb66aab5b 100644 (file)
@@ -29,7 +29,7 @@ public class XDGFRelation extends POIXMLRelation {
     /**
      * A map to lookup POIXMLRelation by its relation type
      */
-    protected static final Map<String, XDGFRelation> _table = new HashMap<String, XDGFRelation>();
+    private static final Map<String, XDGFRelation> _table = new HashMap<String, XDGFRelation>();
 
     public static final XDGFRelation DOCUMENT = new XDGFRelation(
             "application/vnd.ms-visio.drawing.main+xml",
index 5ea703ee6952570dfb7738293247508fab94bc12..f3f59b918ab13da7e0447ee5eb3b57987cf1c292 100644 (file)
@@ -30,7 +30,7 @@ public class XSLFRelation extends POIXMLRelation {
    /**
     * A map to lookup POIXMLRelation by its relation type
     */
-   protected static final Map<String, XSLFRelation> _table = new HashMap<String, XSLFRelation>();
+   private static final Map<String, XSLFRelation> _table = new HashMap<String, XSLFRelation>();
    
    public static final XSLFRelation MAIN = new XSLFRelation(
            "application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml",
index ac2f83567657f2df0a5a30d33cef491c82ba0ce6..9a16f00dc713e7e0b8be7376961f97a3ea5da4cc 100644 (file)
@@ -54,7 +54,7 @@ public final class XSSFRelation extends POIXMLRelation {
     /**
      * A map to lookup POIXMLRelation by its relation type
      */
-    protected static final Map<String, XSSFRelation> _table = new HashMap<String, XSSFRelation>();
+    private static final Map<String, XSSFRelation> _table = new HashMap<String, XSSFRelation>();
 
 
     public static final XSSFRelation WORKBOOK = new XSSFRelation(
index 13b15bf28c565241c8b0c7b73a58c305714fda5d..5c8b385b76e16d0ba0f80911e694f8bfc1a9fa03 100644 (file)
@@ -72,7 +72,7 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
         _cells = new TreeMap<Integer, XSSFCell>();
         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<XSSFRow> {
      */
     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<XSSFRow> {
         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<XSSFRow> {
     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<XSSFRow> {
         if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
            _sheet.getWorkbook().onDeleteFormula(xcell);
         }
-        _cells.remove(new Integer(cell.getColumnIndex()));
+        _cells.remove(cell.getColumnIndex());
     }
 
     /**
index 742720f7885cf2d9344a224d01d23d815b0700c7..74a861b414f004623a57e4836993a33d1adce14a 100644 (file)
@@ -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
index 59b97c3a45dbb95b158fdf19ef65880c4d570668..0afaedc718a3cd99a8ff67b056397e1d588bcec5 100644 (file)
@@ -31,7 +31,7 @@ public final class XWPFRelation extends POIXMLRelation {
     /**
      * A map to lookup POIXMLRelation by its relation type
      */
-    protected static final Map<String, XWPFRelation> _table = new HashMap<String, XWPFRelation>();
+    private static final Map<String, XWPFRelation> _table = new HashMap<String, XWPFRelation>();
 
     public static final XWPFRelation DOCUMENT = new XWPFRelation(
             "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
index d975e730942bfd9569e22fd62ce51c2612d257f2..a8847d07266830887f25f46c5374d89b62678e4c 100644 (file)
@@ -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)) {
index b828886c9536f9bcb52f926418f133efe3d37c26..8ca4678a290f093230d6d63d1142556465e09e4a 100644 (file)
@@ -381,6 +381,7 @@ public abstract class HSLFSimpleShape extends HSLFShape implements SimpleShape<H
 
     public Shadow<HSLFShape,HSLFTextParagraph> getShadow() {
         AbstractEscherOptRecord opt = getEscherOptRecord();
+        if (opt == null) return null;
         EscherProperty shadowType = opt.lookup(EscherProperties.SHADOWSTYLE__TYPE);
         if (shadowType == null) return null;
 
index 750c74ebf38a93ce163e4a06259090fd03b4141f..a1e76d560a07361c31185f079f96b6b4e0b3c753 100644 (file)
@@ -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 {
index a61db1bd24f740295b1d3e4507e60e93c49dac3f..3cbd3f085a7df62c935d7ed7b943a060754c6d1c 100644 (file)
@@ -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
index 14b4fbfc1dd49a037c43e19a64944a032e239564..726c4e86faa3b4f881d833ac1eecb6ffa0e17b3a 100644 (file)
 
 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();
     }
 }
index 705e4ae91dfa28a0faf1b0199177196c230ea8c3..95d173aa3e5963a1401e41bfc742493fcbd2a175 100644 (file)
@@ -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);