sonar fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894360 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2021-10-18 17:40:47 +00:00
parent 787af858e7
commit 611f5273fd
13 changed files with 97 additions and 66 deletions

View 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++) {

View 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()};

View 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 {

View 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

View 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");
}
static final Set<String> OLD_FILES = new HashSet<>(Arrays.asList(
"PPT95.ppt", "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");
}
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"
));
protected static final Map<String,Class<? extends Throwable>> EXCLUDED =
new HashMap<>();
static final Map<String,Class<? extends Throwable>> EXCLUDED = new HashMap<>();
public static Stream<Arguments> files() {
String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY);

View 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>

View 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();
/**

View 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();

View 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 {

View File

@ -384,6 +384,7 @@ public interface TextParagraph<
*
* @since POI 4.0.0
*/
@SuppressWarnings("java:S1452")
List<? extends TabStop> getTabStops();
/**

View 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
*

View 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() {}

View 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) {