Sonar fix - Suppress "Make sure that command line arguments are used safely here." for examples

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876766 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2020-04-20 20:57:37 +00:00
parent 30280a9e5a
commit 65c8c6cd11
35 changed files with 130 additions and 65 deletions

View File

@ -30,7 +30,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/**
* Demonstrates how you can extract embedded data from a .xls file
*/
@SuppressWarnings({"java:S106","java:S4823"})
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class EmbeddedObjects {
private EmbeddedObjects() {}

View File

@ -32,6 +32,7 @@ import org.apache.poi.hwpf.usermodel.CharacterRun;
import org.apache.poi.hwpf.usermodel.Paragraph;
import org.apache.poi.hwpf.usermodel.Range;
@SuppressWarnings({"java:S106","java:S4823"})
public final class Word2Forrest
{
Writer _out;

View File

@ -199,6 +199,7 @@ import org.apache.poi.util.IOUtils;
* 2mm have been noted in testing. Further investigation will
* continue to rectify this issue.
*/
@SuppressWarnings({"java:S106","java:S4823"})
public class AddDimensionedImage {
// Four constants that determine how - and indeed whether - the rows

View File

@ -45,8 +45,8 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
*
* @author Yegor Kozlov
*/
@SuppressWarnings("java:S1192")
public class BusinessPlan {
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class BusinessPlan {
private static final String[] titles = {
"ID", "Project Name", "Owner", "Days", "Start", "End"};
@ -88,6 +88,8 @@ public class BusinessPlan {
null, null, null, null, null, "x", null, null, null, null, null},
};
private BusinessPlan() {}
public static void main(String[] args) throws Exception {
Workbook wb;

View File

@ -17,16 +17,26 @@
package org.apache.poi.ss.examples;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.io.FileOutputStream;
import java.util.Calendar;
import java.util.Map;
import java.util.HashMap;
import java.util.Map;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* A monthly calendar created using Apache POI. Each month is on a separate sheet.
@ -37,7 +47,8 @@ import java.util.HashMap;
*
* @author Yegor Kozlov
*/
public class CalendarDemo {
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class CalendarDemo {
private static final String[] days = {
"Sunday", "Monday", "Tuesday",
@ -47,6 +58,8 @@ public class CalendarDemo {
"January", "February", "March","April", "May", "June","July", "August",
"September","October", "November", "December"};
private CalendarDemo() {}
public static void main(String[] args) throws Exception {
Calendar calendar = Calendar.getInstance();

View File

@ -37,7 +37,10 @@ import org.apache.poi.xssf.usermodel.XSSFFont;
/**
* Demonstrates how to read excel styles for cells
*/
public class CellStyleDetails {
@SuppressWarnings({"java:S106","java:S4823"})
public final class CellStyleDetails {
private CellStyleDetails() {}
public static void main(String[] args) throws Exception {
if(args.length == 0) {
throw new IllegalArgumentException("Filename must be given");

View File

@ -57,8 +57,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* http://www.contextures.com/xlcondformat03.html
* </p>
*/
@SuppressWarnings("java:S1192")
public class ConditionalFormats {
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class ConditionalFormats {
private ConditionalFormats() {}
/**
* generates a sample workbook with conditional formatting,

View File

@ -42,7 +42,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* org.apache.poi.ss.examples.ConditionalFormats
* </p>
*/
public class DrawingBorders {
@SuppressWarnings({"java:S106","java:S4823"})
public final class DrawingBorders {
private DrawingBorders() {}
public static void main(String[] args) throws IOException {
try (Workbook wb = (args.length > 0 && args[0].equals("-xls"))

View File

@ -80,7 +80,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* }
* </pre>
*/
@SuppressWarnings("java:S1192")
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class ExcelComparator {
private static final String CELL_DATA_DOES_NOT_MATCH = "Cell Data does not Match ::";

View File

@ -43,8 +43,11 @@ import org.apache.xmlbeans.XmlException;
* Loads embedded resources from Workbooks. Code taken from the website:
* https://poi.apache.org/spreadsheet/quick-guide.html#Embedded
*/
public class LoadEmbedded {
public static void main(String[] args) throws IOException, EncryptedDocumentException, OpenXML4JException, XmlException {
@SuppressWarnings({"java:S106","java:S4823"})
public final class LoadEmbedded {
private LoadEmbedded() {}
public static void main(String[] args) throws IOException, EncryptedDocumentException, OpenXML4JException, XmlException {
Workbook wb = WorkbookFactory.create(new File(args[0]));
loadEmbedded(wb);
}

View File

@ -45,8 +45,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
*
* @author Yegor Kozlov
*/
@SuppressWarnings("java:S1192")
public class LoanCalculator {
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class LoanCalculator {
private LoanCalculator() {}
public static void main(String[] args) throws Exception {
Workbook wb;

View File

@ -42,8 +42,10 @@ import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@SuppressWarnings("java:S1192")
public class SSPerformanceTest {
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class SSPerformanceTest {
private SSPerformanceTest() {}
public static void main(String[] args) throws IOException {
if (args.length < 4) {
usage("need at least four command arguments");

View File

@ -44,18 +44,20 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
*
* @author Yegor Kozlov
*/
@SuppressWarnings("java:S1192")
public class TimesheetDemo {
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class TimesheetDemo {
private static final String[] titles = {
"Person", "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
"Total\nHrs", "Overtime\nHrs", "Regular\nHrs"
};
private static Object[][] sample_data = {
private static final Object[][] sample_data = {
{"Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0},
{"Gisella Bronzetti", "GB", 4.0, 3.0, 1.0, 3.5, null, null, 4.0},
};
private TimesheetDemo() {}
public static void main(String[] args) throws Exception {
Workbook wb;

View File

@ -129,6 +129,7 @@ import org.apache.poi.ss.usermodel.WorkbookFactory;
* either obeying Excel's or UNIX formatting
* conventions.
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class ToCSV {
private Workbook workbook;

View File

@ -45,6 +45,7 @@ import org.apache.poi.ss.util.CellReference;
* files using Apache POI, along with how to handle errors whilst
* doing so.
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class CheckFunctionsSupported {
public static void main(String[] args) throws Exception {
if (args.length < 1) {
@ -96,8 +97,8 @@ public class CheckFunctionsSupported {
}
}
private Workbook workbook;
private FormulaEvaluator evaluator;
private final Workbook workbook;
private final FormulaEvaluator evaluator;
public CheckFunctionsSupported(Workbook workbook) {
this.workbook = workbook;
this.evaluator = workbook.getCreationHelper().createFormulaEvaluator();

View File

@ -16,11 +16,11 @@
==================================================================== */
package org.apache.poi.ss.examples.formula;
import java.io.File ;
import java.io.File;
import org.apache.poi.ss.formula.functions.FreeRefFunction ;
import org.apache.poi.ss.formula.udf.DefaultUDFFinder ;
import org.apache.poi.ss.formula.udf.UDFFinder ;
import org.apache.poi.ss.formula.functions.FreeRefFunction;
import org.apache.poi.ss.formula.udf.DefaultUDFFinder;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
@ -28,16 +28,19 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellReference ;
import org.apache.poi.ss.util.CellReference;
/**
* An example class of how to invoke a User Defined Function for a given
* XLS instance using POI's UDFFinder implementation.
*/
public class UserDefinedFunctionExample {
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class UserDefinedFunctionExample {
public static void main( String[] args ) throws Exception {
private UserDefinedFunctionExample() {}
public static void main(String[] args ) throws Exception {
if( args.length != 2 ) {
// e.g. src/examples/src/org/apache/poi/ss/examples/formula/mortgage-calculation.xls Sheet1!B4

View File

@ -53,8 +53,8 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* This example shows how to display a spreadsheet in HTML using the classes for
* spreadsheet display.
*/
@SuppressWarnings("java:S1192")
public class ToHtml {
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class ToHtml {
private final Workbook wb;
private final Appendable output;
private boolean completeHTML;

View File

@ -41,6 +41,7 @@ import org.apache.poi.xddf.usermodel.chart.XDDFNumericalDataSource;
/**
* Build a bar chart from a template pptx
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class BarChartDemo {
private BarChartDemo() {}

View File

@ -49,6 +49,7 @@ import org.apache.poi.xddf.usermodel.chart.XDDFValueAxis;
/**
* Build a chart without reading template file
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class ChartFromScratch {
private ChartFromScratch() {}

View File

@ -25,16 +25,16 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.PackagePart;
/**
* Demonstrates how you can extract data from a .pptx file
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class DataExtraction {
private DataExtraction() {}
public static void main(String[] args) throws IOException, OpenXML4JException {
public static void main(String[] args) throws IOException {
PrintStream out = System.out;

View File

@ -25,6 +25,7 @@ import java.io.FileOutputStream;
/**
* Merge multiple pptx presentations together
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class MergePresentations {
private MergePresentations() {}

View File

@ -38,6 +38,7 @@ import org.apache.poi.xddf.usermodel.chart.XDDFPieChartData;
/**
* Build a pie chart from a template pptx
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class PieChartDemo {
private PieChartDemo() {}

View File

@ -31,6 +31,7 @@ import org.apache.poi.xslf.usermodel.XSLFTextShape;
/**
* Reading a .pptx presentation and printing basic shape properties
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class Step1 {
private Step1() {}

View File

@ -65,6 +65,7 @@ import org.xml.sax.XMLReader;
* {@link SheetContentsHandler} and no SAX code needed of
* your own!
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class XLSX2CSV {
/**
* Uses the XSSF Event SAX helpers to do most of the work

View File

@ -42,6 +42,7 @@ import org.xml.sax.helpers.DefaultHandler;
* See {@link XLSX2CSV} for a fuller example of doing
* XSLX processing with the XSSF Event code.
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class FromHowTo {
public void processFirstSheet(String filename) throws Exception {
try (OPCPackage pkg = OPCPackage.open(filename, PackageAccess.READ)) {

View File

@ -35,10 +35,10 @@ import org.apache.poi.xssf.usermodel.examples.LoadPasswordProtectedXlsx;
* <li><code>AesZipFileZipEntrySource</code> is used to ensure that temp files are encrypted.
* </ul><p>
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class LoadPasswordProtectedXlsxStreaming {
private LoadPasswordProtectedXlsxStreaming() {
}
private LoadPasswordProtectedXlsxStreaming() {}
public static void main(String[] args) throws Exception {
LoadPasswordProtectedXlsx.execute(args, LoadPasswordProtectedXlsxStreaming::printSheetCount);

View File

@ -46,7 +46,10 @@ import org.apache.poi.xssf.streaming.SXSSFSheet;
* <li><code>SXSSFWorkbookWithCustomZipEntrySource</code> extends SXSSFWorkbook to ensure temp files are encrypted.
* </ul><p>
*/
public class SavePasswordProtectedXlsx {
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class SavePasswordProtectedXlsx {
private SavePasswordProtectedXlsx() {}
public static void main(String[] args) throws Exception {
if(args.length != 2) {

View File

@ -16,17 +16,20 @@
==================================================================== */
package org.apache.poi.xssf.usermodel.examples;
import java.io.ByteArrayOutputStream;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xssf.extractor.XSSFExportToXml;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFMap;
import java.io.ByteArrayOutputStream;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* Print all custom XML mappings registered in the given workbook
*/
public class CustomXMLMapping {
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class CustomXMLMapping {
private CustomXMLMapping() {}
public static void main(String[] args) throws Exception {
try (OPCPackage pkg = OPCPackage.open(args[0]);

View File

@ -29,7 +29,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* Iterate over rows and cells
*/
public class IterateCells {
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class IterateCells {
private IterateCells() {}
public static void main(String[] args) throws IOException {
try (

View File

@ -37,8 +37,11 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
* <li><code>AesZipFileZipEntrySource</code> is used to ensure that temp files are encrypted.
* </ul><p>
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class LoadPasswordProtectedXlsx {
private LoadPasswordProtectedXlsx() {}
public interface EncryptionHandler {
void handle(final InputStream inputStream) throws Exception;
}

View File

@ -35,7 +35,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* Demonstrates how to insert pictures in a SpreadsheetML document
*/
public class WorkingWithPictures {
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class WorkingWithPictures {
private WorkingWithPictures() {}
public static void main(String[] args) throws IOException {
//create a new workbook

View File

@ -43,6 +43,7 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
/**
* Build a bar chart from a template docx
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class BarChartExample {
private BarChartExample() {}

View File

@ -49,6 +49,7 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
/**
* Build a chart without reading template file
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class ChartFromScratch {
private ChartFromScratch() {}

View File

@ -33,6 +33,7 @@ import org.apache.poi.xwpf.usermodel.XWPFRun;
/**
* Demonstrates how to add pictures in a .docx document
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public final class SimpleImages {
private SimpleImages() {}

View File

@ -46,6 +46,7 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
* This code was successfully tested with the following file from the POI test collection:
* http://svn.apache.org/repos/asf/poi/trunk/test-data/document/EmbeddedDocument.docx
*/
@SuppressWarnings({"java:S106","java:S4823","java:S1192"})
public class UpdateEmbeddedDoc {
private XWPFDocument doc;