poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1839745 - in /poi/trunk/src: java/org/apache/poi/poifs/filesystem/ java/org/apache/poi/poifs/nio/ java/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/openxml4j/opc/ ooxml/java/org/apache/poi/xddf/usermodel/text/ ooxml/java/org/apac...
Date Fri, 31 Aug 2018 11:56:18 GMT
Author: kiwiwings
Date: Fri Aug 31 11:56:18 2018
New Revision: 1839745

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

Modified:
    poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java
    poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/TableStyleType.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
    poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPiece.java

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java?rev=1839745&r1=1839744&r2=1839745&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java Fri Aug 31 11:56:18
2018
@@ -159,6 +159,11 @@ public final class EntryUtils {
         }
 
         @Override
+        public int hashCode() {
+            return dir.getName().hashCode();
+        }
+
+        @Override
         public boolean equals(Object other) {
             if (!(other instanceof DirectoryDelegate)) {
                 return false;
@@ -192,6 +197,11 @@ public final class EntryUtils {
         }
 
         @Override
+        public int hashCode() {
+            return doc.getName().hashCode();
+        }
+
+        @Override
         public boolean equals(Object other) {
             if (!(other instanceof DocumentDelegate)) {
                 return false;

Modified: poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java?rev=1839745&r1=1839744&r2=1839745&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java Fri Aug 31 11:56:18
2018
@@ -127,9 +127,10 @@ public class FileBackedDataSource extend
    @Override
    public void copyTo(OutputStream stream) throws IOException {
       // Wrap the OutputSteam as a channel
-      WritableByteChannel out = Channels.newChannel(stream);
-      // Now do the transfer
-      channel.transferTo(0, channel.size(), out);
+      try (WritableByteChannel out = Channels.newChannel(stream)) {
+          // Now do the transfer
+          channel.transferTo(0, channel.size(), out);
+      }
    }
 
    @Override

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/TableStyleType.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/TableStyleType.java?rev=1839745&r1=1839744&r2=1839745&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/TableStyleType.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/TableStyleType.java Fri Aug 31 11:56:18
2018
@@ -65,7 +65,7 @@ public enum TableStyleType {
             // could do fancy math, but tables can't be that wide, a simple loop is fine
             // if not in this type of stripe, return null
             while (firstStart <= c) {
-                if (c >= firstStart && c <= secondStart -1) {
+                if (c <= secondStart -1) {
                     return new CellRangeAddress(table.getStartRowIndex(), table.getEndRowIndex(),
firstStart, secondStart - 1);
                 }
                 firstStart = secondStart + c2Stripe;
@@ -121,7 +121,7 @@ public enum TableStyleType {
             // could do fancy math, but tables can't be that wide, a simple loop is fine
             // if not in this type of stripe, return null
             while (firstStart <= c) {
-                if (c >= firstStart && c <= secondStart -1) {
+                if (c <= secondStart -1) {
                     return new CellRangeAddress(firstStart, secondStart - 1, table.getStartColIndex(),
table.getEndColIndex());
                 }
                 firstStart = secondStart + c2Stripe;

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java?rev=1839745&r1=1839744&r2=1839745&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java Fri Aug 31 11:56:18
2018
@@ -101,7 +101,7 @@ public final class ZipPackage extends OP
      */
     ZipPackage(InputStream in, PackageAccess access) throws IOException {
         super(access);
-        ZipArchiveThresholdInputStream zis = ZipHelper.openZipStream(in);
+        ZipArchiveThresholdInputStream zis = ZipHelper.openZipStream(in); // NOSONAR
         try {
             this.zipArchive = new ZipInputStreamZipEntrySource(zis);
         } catch (final IOException e) {

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java?rev=1839745&r1=1839744&r2=1839745&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextParagraph.java Fri
Aug 31 11:56:18 2018
@@ -24,6 +24,8 @@ import java.util.List;
 import java.util.Optional;
 import java.util.function.Function;
 
+import org.apache.commons.collections4.iterators.IteratorIterable;
+import org.apache.commons.collections4.iterators.ReverseListIterator;
 import org.apache.poi.util.Beta;
 import org.apache.poi.util.Internal;
 import org.apache.poi.util.LocaleUtil;
@@ -97,8 +99,8 @@ public class XDDFTextParagraph {
     public XDDFTextRun appendLineBreak() {
         CTTextLineBreak br = _p.addNewBr();
         // by default, line break has the font properties of the last text run
-        for (int i = _runs.size() - 1; i <= 0; i--) {
-            CTTextCharacterProperties prevProps = _runs.get(i).getProperties();
+        for (XDDFTextRun tr : new IteratorIterable<>(new ReverseListIterator<>(_runs)))
{
+            CTTextCharacterProperties prevProps = tr.getProperties();
             // let's find one that is not undefined
             if (prevProps != null) {
                 br.setRPr((CTTextCharacterProperties) prevProps.copy());

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java?rev=1839745&r1=1839744&r2=1839745&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java Fri Aug 31 11:56:18
2018
@@ -931,8 +931,10 @@ public class SXSSFWorkbook implements Wo
             }
 
             //Substitute the template entries with the generated sheet data files
-            final ZipEntrySource source = new ZipFileZipEntrySource(new ZipSecureFile(tmplFile));
-            injectData(source, stream);
+            try (ZipSecureFile zf = new ZipSecureFile(tmplFile);
+                 ZipFileZipEntrySource source = new ZipFileZipEntrySource(zf)) {
+                injectData(source, stream);
+            }
         } finally {
             deleted = tmplFile.delete();
         }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java?rev=1839745&r1=1839744&r2=1839745&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java Fri Aug 31 11:56:18
2018
@@ -292,7 +292,7 @@ public class XWPFRun implements ISDTCont
         String color = null;
         if (run.isSetRPr()) {
             CTRPr pr = getRunProperties(false);
-            if (pr.isSetColor()) {
+            if (pr != null && pr.isSetColor()) {
                 CTColor clr = pr.getColor();
                 color = clr.xgetVal().getStringValue();
             }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java?rev=1839745&r1=1839744&r2=1839745&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java Fri Aug
31 11:56:18 2018
@@ -46,8 +46,8 @@ import org.apache.poi.hslf.model.MovieSh
 import org.apache.poi.hslf.record.*;
 import org.apache.poi.hslf.record.SlideListWithText.SlideAtomsSet;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.poifs.filesystem.Ole10Native;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.sl.usermodel.MasterSheet;
 import org.apache.poi.sl.usermodel.PictureData.PictureType;
 import org.apache.poi.sl.usermodel.Resources;
@@ -595,6 +595,9 @@ public final class HSLFSlideShow impleme
 		// The order of slides is defined by the order of slide atom sets in the
 		// SlideListWithText container.
 		SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
+		if (slwt == null) {
+			throw new IllegalStateException("Slide record not defined.");
+		}
 		SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
 
 		SlideAtomsSet tmp = sas[oldSlideNumber - 1];
@@ -635,6 +638,9 @@ public final class HSLFSlideShow impleme
 		}
 
 		SlideListWithText slwt = _documentRecord.getSlideSlideListWithText();
+		if (slwt == null) {
+			throw new IllegalStateException("Slide record not defined.");
+		}
 		SlideAtomsSet[] sas = slwt.getSlideAtomsSets();
 
 		List<Record> records = new ArrayList<>();
@@ -678,12 +684,14 @@ public final class HSLFSlideShow impleme
 						records.addAll(Arrays.asList(ns.getSlideRecords()));
 					}
 				}
+
+				if (!na.isEmpty()) {
+					nslwt.setSlideAtomsSets(na.toArray(new SlideAtomsSet[0]));
+					nslwt.setChildRecord(records.toArray(new Record[0]));
+				}
 			}
 			if (na.isEmpty()) {
 				_documentRecord.removeSlideListWithText(nslwt);
-			} else {
-				nslwt.setSlideAtomsSets(na.toArray(new SlideAtomsSet[0]));
-				nslwt.setChildRecord(records.toArray(new Record[0]));
 			}
 		}
 
@@ -1113,7 +1121,7 @@ public final class HSLFSlideShow impleme
     }
 
     @Override
-    public MasterSheet<HSLFShape,HSLFTextParagraph> createMasterSheet() throws IOException
{
+    public MasterSheet<HSLFShape,HSLFTextParagraph> createMasterSheet() {
 		// TODO implement or throw exception if not supported
         return null;
     }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java?rev=1839745&r1=1839744&r2=1839745&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToTextConverter.java Fri
Aug 31 11:56:18 2018
@@ -17,6 +17,7 @@
 package org.apache.poi.hwpf.converter;
 
 import java.io.File;
+import java.io.IOException;
 import java.io.StringWriter;
 import java.lang.reflect.Method;
 import java.util.List;
@@ -114,14 +115,13 @@ public class WordToTextConverter extends
         serializer.transform( domSource, streamResult );
     }
 
-    static Document process( File docFile ) throws Exception
-    {
-        final HWPFDocumentCore wordDocument = AbstractWordUtils
-                .loadDoc( docFile );
-        WordToTextConverter wordToTextConverter = new WordToTextConverter(
-                XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().newDocument()
);
-        wordToTextConverter.processDocument( wordDocument );
-        return wordToTextConverter.getDocument();
+    private static Document process( File docFile ) throws IOException, ParserConfigurationException
{
+        try (final HWPFDocumentCore wordDocument = AbstractWordUtils.loadDoc( docFile ))
{
+            WordToTextConverter wordToTextConverter = new WordToTextConverter(
+                    XMLHelper.getDocumentBuilderFactory().newDocumentBuilder().newDocument());
+            wordToTextConverter.processDocument(wordDocument);
+            return wordToTextConverter.getDocument();
+        }
     }
 
     private AtomicInteger noteCounters = new AtomicInteger( 1 );
@@ -153,12 +153,14 @@ public class WordToTextConverter extends
      * @param document
      *            XML DOM Document used as storage for text pieces
      */
-    public WordToTextConverter( Document document )
+    @SuppressWarnings("WeakerAccess")
+    public WordToTextConverter(Document document )
     {
         this.textDocumentFacade = new TextDocumentFacade( document );
     }
 
-    public WordToTextConverter( TextDocumentFacade textDocumentFacade )
+    @SuppressWarnings("unused")
+    public WordToTextConverter(TextDocumentFacade textDocumentFacade )
     {
         this.textDocumentFacade = textDocumentFacade;
     }
@@ -192,6 +194,7 @@ public class WordToTextConverter extends
         return stringWriter.toString();
     }
 
+    @SuppressWarnings("WeakerAccess")
     public boolean isOutputSummaryInformation()
     {
         return outputSummaryInformation;
@@ -275,7 +278,7 @@ public class WordToTextConverter extends
 
         currentBlock.appendChild( textDocumentFacade.createText( " ("
                 + UNICODECHAR_ZERO_WIDTH_SPACE
-                + hyperlink.replaceAll( "\\/", UNICODECHAR_ZERO_WIDTH_SPACE
+                + hyperlink.replaceAll( "/", UNICODECHAR_ZERO_WIDTH_SPACE
                         + "\\/" + UNICODECHAR_ZERO_WIDTH_SPACE )
                 + UNICODECHAR_ZERO_WIDTH_SPACE + ")" ) );
     }
@@ -307,9 +310,7 @@ public class WordToTextConverter extends
         block.appendChild( textDocumentFacade.createText( "\n" ) );
     }
 
-    protected void processNote( HWPFDocument wordDocument, Element block,
-            Range noteTextRange )
-    {
+    private void processNote( HWPFDocument wordDocument, Element block, Range noteTextRange
) {
         final int noteIndex = noteCounters.getAndIncrement();
         block.appendChild( textDocumentFacade
                 .createText( UNICODECHAR_ZERO_WIDTH_SPACE + "[" + noteIndex
@@ -457,7 +458,8 @@ public class WordToTextConverter extends
         }
     }
 
-    public void setOutputSummaryInformation( boolean outputDocumentInformation )
+    @SuppressWarnings("unused")
+    public void setOutputSummaryInformation(boolean outputDocumentInformation )
     {
         this.outputSummaryInformation = outputDocumentInformation;
     }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPiece.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPiece.java?rev=1839745&r1=1839744&r2=1839745&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPiece.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPiece.java Fri Aug 31 11:56:18
2018
@@ -18,6 +18,8 @@
 package org.apache.poi.hwpf.model;
 
 
+import java.util.Arrays;
+
 import org.apache.poi.util.Internal;
 import org.apache.poi.util.NotImplemented;
 
@@ -102,6 +104,12 @@ public class OldTextPiece extends TextPi
         return 42; // any arbitrary constant will do
     }
 
+    @Override
+    public boolean equals(Object other) {
+        return other instanceof OldTextPiece &&
+            Arrays.equals(rawBytes, ((OldTextPiece)other).rawBytes);
+    }
+
     public String toString() {
         return "OldTextPiece from " + getStart() + " to " + getEnd() + " ("
                 + getPieceDescriptor() + ")";



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message