]> source.dussan.org Git - poi.git/commitdiff
sonar fixes
authorAndreas Beeker <kiwiwings@apache.org>
Mon, 18 Oct 2021 17:40:47 +0000 (17:40 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Mon, 18 Oct 2021 17:40:47 +0000 (17:40 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894360 13f79535-47bb-0310-9956-ffa450edef68

13 files changed:
poi-examples/src/main/java/org/apache/poi/examples/ss/CellStyleDetails.java
poi-examples/src/main/java/org/apache/poi/examples/ss/formula/UserDefinedFunctionExample.java
poi-integration/src/test/java/org/apache/poi/stress/AbstractFileHandler.java
poi-ooxml/src/main/java/org/apache/poi/xssf/model/StylesTable.java
poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java
poi/src/main/java/org/apache/poi/sl/usermodel/Sheet.java
poi/src/main/java/org/apache/poi/sl/usermodel/Slide.java
poi/src/main/java/org/apache/poi/sl/usermodel/SlideShow.java
poi/src/main/java/org/apache/poi/sl/usermodel/SlideShowFactory.java
poi/src/main/java/org/apache/poi/sl/usermodel/TextParagraph.java
poi/src/main/java/org/apache/poi/sl/usermodel/TextRun.java
poi/src/main/java/org/apache/poi/util/GenericRecordUtil.java
poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java

index 6997a9e8fa92bdf888014193f27153aa87ab6a36..ce6927180592a2dfb6ffbc9efdd672c828b2e036 100644 (file)
@@ -47,6 +47,10 @@ public final class CellStyleDetails {
         }
 
         try (Workbook wb = WorkbookFactory.create(new File(args[0]))) {
+            if (wb == null) {
+                System.out.println("Workbook "+args[0]+" can't be loaded.");
+                return;
+            }
             DataFormatter formatter = new DataFormatter();
 
             for (int sn = 0; sn < wb.getNumberOfSheets(); sn++) {
index 939fd9ab9daf29ac31d340f8bb7f3c1ac99ef647..be03faebbbb279754e86bbc43d40fe158336b3b5 100644 (file)
@@ -54,6 +54,10 @@ public final class UserDefinedFunctionExample {
         File workbookFile = new File( args[0] ) ;
 
         try (Workbook workbook = WorkbookFactory.create(workbookFile, null, true)) {
+            if (workbook == null) {
+                System.out.println("Workbook "+workbookFile+" can't be loaded.");
+                return;
+            }
             String[] functionNames = {"calculatePayment"};
             FreeRefFunction[] functionImpls = {new CalculateMortgage()};
 
index 2177af2b6fd611ca3c9e50a785e24eba3ab4586c..fec396281d199474cf6a675a3c38efc66704026f 100644 (file)
@@ -25,6 +25,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -43,23 +44,22 @@ import org.apache.poi.util.IOUtils;
  * in the integration tests, mostly text-extraction related at the moment.
  */
 public abstract class AbstractFileHandler implements FileHandler {
-    public static final Set<String> EXPECTED_EXTRACTOR_FAILURES = new HashSet<>();
-    static {
+    public static final Set<String> EXPECTED_EXTRACTOR_FAILURES = new HashSet<>(Arrays.asList(
         // password protected files without password
         // ... currently none ...
 
         // unsupported file-types, no supported OLE2 parts
-        EXPECTED_EXTRACTOR_FAILURES.add("hmef/quick-winmail.dat");
-        EXPECTED_EXTRACTOR_FAILURES.add("hmef/winmail-sample1.dat");
-        EXPECTED_EXTRACTOR_FAILURES.add("hmef/bug52400-winmail-simple.dat");
-        EXPECTED_EXTRACTOR_FAILURES.add("hmef/bug52400-winmail-with-attachments.dat");
-        EXPECTED_EXTRACTOR_FAILURES.add("hmef/bug63955-winmail.dat");
-        EXPECTED_EXTRACTOR_FAILURES.add("hpsf/Test0313rur.adm");
-        EXPECTED_EXTRACTOR_FAILURES.add("poifs/Notes.ole2");
-        EXPECTED_EXTRACTOR_FAILURES.add("poifs/64322.ole2");
+        "hmef/quick-winmail.dat",
+        "hmef/winmail-sample1.dat",
+        "hmef/bug52400-winmail-simple.dat",
+        "hmef/bug52400-winmail-with-attachments.dat",
+        "hmef/bug63955-winmail.dat",
+        "hpsf/Test0313rur.adm",
+        "poifs/Notes.ole2",
+        "poifs/64322.ole2",
         //commons-compress 1.21 no longer supports truncated files
-        EXPECTED_EXTRACTOR_FAILURES.add("document/truncated62886.docx");
-    }
+        "document/truncated62886.docx"
+    ));
 
     @Override
     public void handleExtracting(File file) throws Exception {
index 20e2e4d9900de8b63d8dc341b12fa53a904ccda9..60b1a9ce426944e94418654a446554392447d81e 100644 (file)
@@ -36,14 +36,17 @@ import java.util.TreeMap;
 import org.apache.poi.ooxml.POIXMLDocumentPart;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.ss.SpreadsheetVersion;
-import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.usermodel.BuiltinFormats;
+import org.apache.poi.ss.usermodel.Color;
+import org.apache.poi.ss.usermodel.FontFamily;
+import org.apache.poi.ss.usermodel.FontScheme;
+import org.apache.poi.ss.usermodel.TableStyle;
 import org.apache.poi.util.Internal;
 import org.apache.poi.xssf.usermodel.CustomIndexedColorMap;
 import org.apache.poi.xssf.usermodel.DefaultIndexedColorMap;
 import org.apache.poi.xssf.usermodel.IndexedColorMap;
 import org.apache.poi.xssf.usermodel.XSSFBuiltinTableStyle;
 import org.apache.poi.xssf.usermodel.XSSFCellStyle;
-import org.apache.poi.xssf.usermodel.XSSFFactory;
 import org.apache.poi.xssf.usermodel.XSSFFont;
 import org.apache.poi.xssf.usermodel.XSSFRelation;
 import org.apache.poi.xssf.usermodel.XSSFTableStyle;
@@ -51,7 +54,24 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
 import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
 import org.apache.xmlbeans.XmlException;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorders;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellStyleXfs;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellXfs;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxf;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxfs;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFills;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFonts;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTNumFmt;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTNumFmts;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyle;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyles;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument;
 
 /**
  * Table of styles shared across all sheets in a workbook.
@@ -173,10 +193,9 @@ public class StylesTable extends POIXMLDocumentPart implements Styles {
      * After this, calls to {@link #getTheme()} won't give null
      */
     public void ensureThemesTable() {
-        if (theme != null) return;
-
-        XSSFFactory factory = workbook == null ? XSSFFactory.getInstance() : workbook.getXssfFactory();
-        setTheme((ThemesTable)workbook.createRelationship(XSSFRelation.THEME, factory));
+        if (theme == null && workbook != null) {
+            setTheme((ThemesTable) workbook.createRelationship(XSSFRelation.THEME, workbook.getXssfFactory()));
+        }
     }
 
     /**
@@ -278,12 +297,12 @@ public class StylesTable extends POIXMLDocumentPart implements Styles {
     }
 
     /**
-     * Puts <code>fmt</code> in the numberFormats map if the format is not
+     * Puts {@code fmt} in the numberFormats map if the format is not
      * already in the the number format style table.
-     * Does nothing if <code>fmt</code> is already in number format style table.
+     * Does nothing if {@code fmt} is already in number format style table.
      *
      * @param fmt the number format to add to number format style table
-     * @return the index of <code>fmt</code> in the number format style table
+     * @return the index of {@code fmt} in the number format style table
      * @throws IllegalStateException if adding the number format to the styles table
      * would exceed the {@link #MAXIMUM_NUMBER_OF_DATA_FORMATS} allowed.
      */
@@ -331,7 +350,7 @@ public class StylesTable extends POIXMLDocumentPart implements Styles {
     /**
      * Add a number format with a specific ID into the numberFormats map.
      * If a format with the same ID already exists, overwrite the format code
-     * with <code>fmt</code>
+     * with {@code fmt}
      * This may be used to override built-in number formats.
      *
      * @param index the number format ID
index 9797cb74c8ecba9f58ede3baa6359d706d6f10db..4a0036b01003cb384f6b29d65f0a353abea7f4f8 100644 (file)
@@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 import java.io.File;
 import java.io.PrintStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -44,23 +45,19 @@ import org.junit.jupiter.params.provider.MethodSource;
 
 @Isolated   // this test changes global static BYTE_ARRAY_MAX_OVERRIDE
 public abstract class BaseTestPPTIterating {
-    protected static final Set<String> OLD_FILES = new HashSet<>();
-    static {
-        OLD_FILES.add("PPT95.ppt");
-        OLD_FILES.add("pp40only.ppt");
-    }
-
-    protected static final Set<String> ENCRYPTED_FILES = new HashSet<>();
-    static {
-        ENCRYPTED_FILES.add("cryptoapi-proc2356.ppt");
-        ENCRYPTED_FILES.add("Password_Protected-np-hello.ppt");
-        ENCRYPTED_FILES.add("Password_Protected-56-hello.ppt");
-        ENCRYPTED_FILES.add("Password_Protected-hello.ppt");
-        ENCRYPTED_FILES.add("ppt_with_png_encrypted.ppt");
-    }
-
-    protected static final Map<String,Class<? extends Throwable>> EXCLUDED =
-            new HashMap<>();
+    static final Set<String> OLD_FILES = new HashSet<>(Arrays.asList(
+        "PPT95.ppt", "pp40only.ppt"
+    ));
+
+    static final Set<String> ENCRYPTED_FILES = new HashSet<>(Arrays.asList(
+        "cryptoapi-proc2356.ppt",
+        "Password_Protected-np-hello.ppt",
+        "Password_Protected-56-hello.ppt",
+        "Password_Protected-hello.ppt",
+        "ppt_with_png_encrypted.ppt"
+    ));
+
+    static final Map<String,Class<? extends Throwable>> EXCLUDED = new HashMap<>();
 
     public static Stream<Arguments> files() {
         String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);
index ab187cbc5d72ac5b4b6b2761c99586d60137d64c..8be7ee46d5d0c49209efee573db240b93638a20c 100644 (file)
@@ -23,6 +23,7 @@ import java.awt.Graphics2D;
 /**
  * Common parent of Slides, Notes and Masters
  */
+@SuppressWarnings("java:S1452")
 public interface Sheet<
     S extends Shape<S,P>,
     P extends TextParagraph<S,P,? extends TextRun>
index 7c0d5661380ec1cadd3c9f7e9cf14402b84bfaf4..ade5b08ed670f6ee6a932756c183f201a12db209 100644 (file)
@@ -58,17 +58,17 @@ public interface Slide<
     boolean getDisplayPlaceholder(Placeholder placeholder);
 
     /**
-     * Sets the slide visibility 
+     * Sets the slide visibility
      *
      * @param hidden slide visibility, if {@code true} the slide is hidden, {@code false} shows the slide
-     * 
+     *
      * @since POI 4.0.0
      */
     void setHidden(boolean hidden);
 
     /**
      * @return the slide visibility, the slide is hidden when {@code true} - or shown when {@code false}
-     * 
+     *
      * @since POI 4.0.0
      */
     boolean isHidden();
@@ -76,6 +76,7 @@ public interface Slide<
     /**
      * @return the comment(s) for this slide
      */
+    @SuppressWarnings("java:S1452")
     List<? extends Comment> getComments();
 
     /**
index eaca055dfeb8baa19fac3dc5d9835fc17cbb0110..1ad08c2c8814fc2d22f8d4c87b8744dc2d8f596c 100644 (file)
@@ -29,6 +29,7 @@ import org.apache.poi.common.usermodel.fonts.FontInfo;
 import org.apache.poi.extractor.POITextExtractor;
 import org.apache.poi.sl.usermodel.PictureData.PictureType;
 
+@SuppressWarnings("java:S1452")
 public interface SlideShow<
     S extends Shape<S,P>,
     P extends TextParagraph<S,P,? extends TextRun>
@@ -58,10 +59,10 @@ public interface SlideShow<
      * @param pgsize page size (in points)
      */
     void setPageSize(Dimension pgsize);
-    
+
     /**
      * Returns all Pictures of this slideshow.
-     * The returned {@link List} is unmodifiable. 
+     * The returned {@link List} is unmodifiable.
      * @return a {@link List} of {@link PictureData}.
      */
     List<? extends PictureData> getPictureData();
@@ -97,10 +98,10 @@ public interface SlideShow<
      * @since 3.15 beta 1
      */
     PictureData addPicture(File pict, PictureType format) throws IOException;
-    
+
     /**
      * check if a picture with this picture data already exists in this presentation
-     * 
+     *
      * @param pictureData The picture data to find in the SlideShow
      * @return {@code null} if picture data is not found in this slideshow
      * @since 3.15 beta 3
@@ -121,7 +122,7 @@ public interface SlideShow<
 
     /**
      * @return an extractor for the slideshow metadata
-     * 
+     *
      * @since POI 4.0.0
      */
     POITextExtractor getMetadataTextExtractor();
index 465c6f978b33384bf0f29484664a06f144eafb44..cb4c81ca7781d29e49d2a624537606f436653a2f 100644 (file)
@@ -35,6 +35,7 @@ import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.FileMagic;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 
+@SuppressWarnings("java:S1452")
 public final class SlideShowFactory {
 
     private static class Singleton {
index a6c4394278affe9f00a47b50cf74e8b59fab7a3a..c0d0c3be3aac30ea2a7026766b4091a382a7b89c 100644 (file)
@@ -384,6 +384,7 @@ public interface TextParagraph<
      *
      * @since POI 4.0.0
      */
+    @SuppressWarnings("java:S1452")
     List<? extends TabStop> getTabStops();
 
     /**
index 7dfd4933d83f8fc1c0905bd467c21a299c08ed21..11bc79c8ecc8f70da23c7bc78068909dca02b112 100644 (file)
@@ -27,7 +27,7 @@ import org.apache.poi.util.Internal;
 /**
  * Some text.
  */
-@SuppressWarnings("unused")
+@SuppressWarnings({"unused","java:S1452"})
 public interface TextRun {
     /**
      * Type of text capitals
@@ -37,7 +37,7 @@ public interface TextRun {
         SMALL,
         ALL
     }
-    
+
     /**
      * Type of placeholder fields
      */
@@ -96,18 +96,18 @@ public interface TextRun {
     void setFontSize(Double fontSize);
 
     /**
-     * Get the font family - convenience method for {@link #getFontInfo(FontGroup)} 
-     * 
+     * Get the font family - convenience method for {@link #getFontInfo(FontGroup)}
+     *
      * @return  font family or null if not set
      */
     String getFontFamily();
 
     /**
      * Get the font family - convenience method for {@link #getFontInfo(FontGroup)}
-     * 
+     *
      * @param fontGroup the font group, i.e. the range of glpyhs to be covered.
-     *    if {@code null}, the font group matching the first character will be returned 
-     * 
+     *    if {@code null}, the font group matching the first character will be returned
+     *
      * @return  font family or null if not set
      */
     String getFontFamily(FontGroup fontGroup);
@@ -128,17 +128,17 @@ public interface TextRun {
      * @param typeface  the font to apply to this text run.
      *      The value of {@code null} removes the run specific font setting, so the default setting is activated again.
      * @param fontGroup the font group, i.e. the range of glpyhs to be covered.
-     *    if {@code null}, the font group matching the first character will be returned 
+     *    if {@code null}, the font group matching the first character will be returned
      */
     void setFontFamily(String typeface, FontGroup fontGroup);
 
     /**
      * Get the font info for the given font group
-     * 
+     *
      * @param fontGroup the font group, i.e. the range of glpyhs to be covered.
-     *    if {@code null}, the font group matching the first character will be returned 
+     *    if {@code null}, the font group matching the first character will be returned
      * @return  font info or {@code null} if not set
-     * 
+     *
      * @since POI 3.17-beta2
      */
     FontInfo getFontInfo(FontGroup fontGroup);
@@ -149,11 +149,11 @@ public interface TextRun {
      * @param fontInfo the font to apply to this text run.
      *      The value of {@code null} removes the run specific font setting, so the default setting is activated again.
      * @param fontGroup the font group, i.e. the range of glpyhs to be covered. defaults to latin, if {@code null}.
-     * 
+     *
      * @since POI 3.17-beta2
      */
     void setFontInfo(FontInfo fontInfo, FontGroup fontGroup);
-    
+
     /**
      * @return true, if text is bold
      */
@@ -165,7 +165,7 @@ public interface TextRun {
      * @param bold set to true for bold text, false for normal weight
      */
     void setBold(boolean bold);
-    
+
     /**
      * @return true, if text is italic
      */
@@ -219,24 +219,24 @@ public interface TextRun {
 
     /**
      * Return the associated hyperlink
-     * 
+     *
      * @return the associated hyperlink or null if no hyperlink was set
-     * 
+     *
      * @since POI 3.14-Beta2
      */
     Hyperlink<?,?> getHyperlink();
-    
-    
+
+
     /**
      * Creates a new hyperlink and assigns it to this text run.
      * If the text run has already a hyperlink assigned, return it instead
      *
      * @return the associated hyperlink
-     * 
+     *
      * @since POI 3.14-Beta2
      */
     Hyperlink<?,?> createHyperlink();
-    
+
     /**
      * Experimental method to determine the field type, e.g. slide number
      *
index f788ec86676da0235fac12ad200b2b1c7a561418..a341b060c3be2457a1378d03687a0fc50bb0559f 100644 (file)
@@ -26,6 +26,7 @@ import java.util.Map;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
+@SuppressWarnings("java:S1452")
 @Internal
 public final class GenericRecordUtil {
     private GenericRecordUtil() {}
index a90f9c94fb2f8736eecc5d75f8b3f533505edfc9..793c1e845fc96cbec5fddea2c23ff71a2358f29b 100644 (file)
@@ -234,6 +234,7 @@ public class GenericRecordXmlWriter implements Closeable {
         printObject("error", errorMsg);
     }
 
+    @SuppressWarnings("java:S1452")
     protected Stream<Map.Entry<String,Supplier<?>>> writeProp(Map.Entry<String,Supplier<?>> me) {
         Object obj = me.getValue().get();
         if (obj == null) {