Author: kiwiwings
Date: Sat Jun  2 21:28:06 2018
New Revision: 1832748

URL: http://svn.apache.org/viewvc?rev=1832748&view=rev
Log:
sonar fixes

Modified:
    poi/trunk/src/java/org/apache/poi/hpsf/Section.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
    
poi/trunk/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java
    poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/SAXHelper.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFChart.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java

Modified: poi/trunk/src/java/org/apache/poi/hpsf/Section.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/Section.java?rev=1832748&r1=1832747&r2=1832748&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/Section.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/Section.java Sat Jun  2 21:28:06 2018
@@ -844,10 +844,10 @@ public class Section {
                 if (cp == CodePageUtil.CP_UNICODE) {
                     pad = 2+((4 - ((nrBytes+2) & 0x3)) & 0x3);
                 }
-                leis.skip(pad);
+                IOUtils.skipFully(leis, pad);
 
                 dic.put(id, str);
-            } catch (RuntimeException ex) {
+            } catch (RuntimeException|IOException ex) {
                 LOG.log(POILogger.WARN, errMsg, ex);
                 isCorrupted = true;
                 break;

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java?rev=1832748&r1=1832747&r2=1832748&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java Sat Jun  
2 21:28:06 2018
@@ -812,6 +812,9 @@ public class DataFormatter implements Ob
      * @return Formatted value
      */
     private String getFormattedDateString(Cell cell, 
ConditionalFormattingEvaluator cfEvaluator) {
+        if (cell == null) {
+            return null;
+        }
         Format dateFormat = getFormat(cell, cfEvaluator);
         if(dateFormat instanceof ExcelStyleDateFormatter) {
            // Hint about the raw excel value
@@ -837,7 +840,9 @@ public class DataFormatter implements Ob
      * @return a formatted number string
      */
     private String getFormattedNumberString(Cell cell, 
ConditionalFormattingEvaluator cfEvaluator) {
-
+        if (cell == null) {
+            return null;
+        }
         Format numberFormat = getFormat(cell, cfEvaluator);
         double d = cell.getNumericCellValue();
         if (numberFormat == null) {

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java?rev=1832748&r1=1832747&r2=1832748&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java 
(original)
+++ 
poi/trunk/src/ooxml/java/org/apache/poi/ooxml/extractor/ExtractorFactory.java 
Sat Jun  2 21:28:06 2018
@@ -146,7 +146,7 @@ public class ExtractorFactory {
             // ensure file-handle release
             IOUtils.closeQuietly(fs);
             throw new IllegalArgumentException("Your File was neither an OLE2 
file, nor an OOXML file");
-        } catch (OpenXML4JException | Error | RuntimeException | IOException | 
XmlException e) {
+        } catch (OpenXML4JException | Error | RuntimeException | IOException | 
XmlException e) { // NOSONAR
             // ensure file-handle release
             IOUtils.closeQuietly(fs);
             throw e;
@@ -245,7 +245,7 @@ public class ExtractorFactory {
 
             throw new IllegalArgumentException("No supported documents found 
in the OOXML package (found "+contentType+")");
 
-        } catch (IOException | Error | RuntimeException | XmlException | 
OpenXML4JException e) {
+        } catch (IOException | Error | RuntimeException | XmlException | 
OpenXML4JException e) { // NOSONAR
             // ensure that we close the package again if there is an error 
opening it, however
             // we need to revert the package to not re-write the file via 
close(), which is very likely not wanted for a TextExtractor!
             pkg.revert();

Modified: poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/SAXHelper.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/SAXHelper.java?rev=1832748&r1=1832747&r2=1832748&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/SAXHelper.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/ooxml/util/SAXHelper.java Sat Jun  
2 21:28:06 2018
@@ -68,7 +68,7 @@ public final class SAXHelper {
             saxFactory = SAXParserFactory.newInstance();
             saxFactory.setValidating(false);
             saxFactory.setNamespaceAware(true);
-        } catch (RuntimeException | Error re) {
+        } catch (RuntimeException | Error re) { // NOSONAR
             // this also catches NoClassDefFoundError, which may be due to a 
local class path issue
             // This may occur if the code is run inside a web container
             // or a restricted JVM

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java?rev=1832748&r1=1832747&r2=1832748&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFPicture.java 
Sat Jun  2 21:28:06 2018
@@ -106,13 +106,12 @@ public final class SXSSFPicture implemen
     @Override
     public void resize(double scale){
         XSSFClientAnchor anchor = getClientAnchor();
-        if (anchor == null) {
+        XSSFClientAnchor pref = getPreferredSize(scale);
+        if (anchor == null || pref == null) {
             logger.log(POILogger.WARN, "picture is not anchored via client 
anchor - ignoring resize call");
             return;
         }
 
-        XSSFClientAnchor pref = getPreferredSize(scale);
-
         int row2 = anchor.getRow1() + (pref.getRow2() - pref.getRow1());
         int col2 = anchor.getCol1() + (pref.getCol2() - pref.getCol1());
 

Modified: 
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java?rev=1832748&r1=1832747&r2=1832748&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPicture.java Sat 
Jun  2 21:28:06 2018
@@ -176,8 +176,11 @@ public final class XSSFPicture extends X
      */
     public void resize(double scaleX, double scaleY){
         XSSFClientAnchor anchor = getClientAnchor();
-
         XSSFClientAnchor pref = getPreferredSize(scaleX,scaleY);
+        if (anchor == null || pref == null) {
+            logger.log(POILogger.WARN, "picture is not anchored via client 
anchor - ignoring resize call");
+            return;
+        }
 
         int row2 = anchor.getRow1() + (pref.getRow2() - pref.getRow1());
         int col2 = anchor.getCol1() + (pref.getCol2() - pref.getCol1());

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFChart.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFChart.java?rev=1832748&r1=1832747&r2=1832748&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFChart.java 
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFChart.java Sat 
Jun  2 21:28:06 2018
@@ -92,21 +92,11 @@ public class XWPFChart extends XDDFChart
 
     public Long getChecksum() {
         if (this.checksum == null) {
-            InputStream is = null;
             byte[] data;
-            try {
-                is = getPackagePart().getInputStream();
+            try (InputStream is = getPackagePart().getInputStream()) {
                 data = IOUtils.toByteArray(is);
             } catch (IOException e) {
                 throw new POIXMLException(e);
-            } finally {
-                try {
-                    if (is != null) {
-                        is.close();
-                    }
-                } catch (IOException e) {
-                    throw new POIXMLException(e);
-                }
             }
             this.checksum = IOUtils.calculateChecksum(data);
         }

Modified: 
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java?rev=1832748&r1=1832747&r2=1832748&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/record/TextRulerAtom.java 
Sat Jun  2 21:28:06 2018
@@ -29,6 +29,7 @@ import java.util.List;
 import org.apache.poi.hslf.model.textproperties.HSLFTabStop;
 import org.apache.poi.hslf.model.textproperties.HSLFTabStopPropCollection;
 import org.apache.poi.util.BitField;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.LittleEndianByteArrayInputStream;
 import org.apache.poi.util.LittleEndianOutputStream;
@@ -89,7 +90,7 @@ public final class TextRulerAtom extends
 
         try {
             // Get the header.
-            leis.read(_header);
+            IOUtils.readFully(leis, _header);
 
             // Get the record data.
             read(leis);



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to