]> source.dussan.org Git - poi.git/commitdiff
SonarQube fixes
authorAndreas Beeker <kiwiwings@apache.org>
Tue, 3 Jan 2017 01:02:33 +0000 (01:02 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Tue, 3 Jan 2017 01:02:33 +0000 (01:02 +0000)
add Iterable interface to EscherContainerRecord / deprecate getChildIterator()

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1777046 13f79535-47bb-0310-9956-ffa450edef68

13 files changed:
src/java/org/apache/poi/ddf/EscherContainerRecord.java
src/java/org/apache/poi/hssf/dev/BiffViewer.java
src/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java
src/java/org/apache/poi/hssf/model/InternalWorkbook.java
src/java/org/apache/poi/hssf/record/common/UnicodeString.java
src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/scratchpad/src/org/apache/poi/hslf/record/PPDrawingGroup.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFGroupShape.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSheet.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java
src/scratchpad/src/org/apache/poi/hssf/usermodel/HSSFChart.java

index 3b26d4211aef7216f2a346989e88aa717eb74576..e570084b249259af684cbf752c807346e198ea66 100644 (file)
 package org.apache.poi.ddf;
 
 import java.io.PrintWriter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
 
 import org.apache.poi.util.HexDump;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Removal;
 
 /**
  * Escher container records store other escher records as children.
@@ -31,7 +35,7 @@ import org.apache.poi.util.POILogger;
  * the standard header used by all escher records.  This one record is
  * used to represent many different types of records.
  */
-public final class EscherContainerRecord extends EscherRecord {
+public final class EscherContainerRecord extends EscherRecord implements Iterable<EscherRecord> {
     public static final short DGG_CONTAINER    = (short)0xF000;
     public static final short BSTORE_CONTAINER = (short)0xF001;
     public static final short DG_CONTAINER     = (short)0xF002;
@@ -97,17 +101,13 @@ public final class EscherContainerRecord extends EscherRecord {
         LittleEndian.putShort(data, offset, getOptions());
         LittleEndian.putShort(data, offset+2, getRecordId());
         int remainingBytes = 0;
-        Iterator<EscherRecord> iterator = _childRecords.iterator();
-        while (iterator.hasNext()) {
-            EscherRecord r = iterator.next();
+        for (EscherRecord r : this) {
             remainingBytes += r.getRecordSize();
         }
         remainingBytes += _remainingLength;
         LittleEndian.putInt(data, offset+4, remainingBytes);
         int pos = offset+8;
-        iterator = _childRecords.iterator();
-        while (iterator.hasNext()) {
-            EscherRecord r = iterator.next();
+        for (EscherRecord r : this) {
             pos += r.serialize(pos, data, listener );
         }
 
@@ -118,9 +118,7 @@ public final class EscherContainerRecord extends EscherRecord {
     @Override
     public int getRecordSize() {
         int childRecordsSize = 0;
-        Iterator<EscherRecord> iterator = _childRecords.iterator();
-        while (iterator.hasNext()) {
-            EscherRecord r = iterator.next();
+        for (EscherRecord r : this) {
             childRecordsSize += r.getRecordSize();
         }
         return 8 + childRecordsSize;
@@ -134,9 +132,7 @@ public final class EscherContainerRecord extends EscherRecord {
      * @return true, if any child has the given recordId
      */
     public boolean hasChildOfType(short recordId) {
-        Iterator<EscherRecord> iterator = _childRecords.iterator();
-        while (iterator.hasNext()) {
-            EscherRecord r = iterator.next();
+        for (EscherRecord r : this) {
             if(r.getRecordId() == recordId) {
                 return true;
             }
@@ -158,8 +154,20 @@ public final class EscherContainerRecord extends EscherRecord {
 
     /**
      * @return an iterator over the child records
+     * @deprecated POI 3.16 beta 1. use iterator() or loop over the container record instead,
+     *     e.g. "for (EscherRecord r : container) ..."
      */
+    @Removal(version="3.18")
+    @Deprecated
     public Iterator<EscherRecord> getChildIterator() {
+        return iterator();
+    }
+    
+    /**
+     * @return an iterator over the child records
+     */
+    @Override
+    public Iterator<EscherRecord> iterator() {
         return Collections.unmodifiableList(_childRecords).iterator();
     }
 
@@ -195,9 +203,7 @@ public final class EscherContainerRecord extends EscherRecord {
      */
     public List<EscherContainerRecord> getChildContainers() {
         List<EscherContainerRecord> containers = new ArrayList<EscherContainerRecord>();
-        Iterator<EscherRecord> iterator = _childRecords.iterator();
-        while (iterator.hasNext()) {
-            EscherRecord r = iterator.next();
+        for (EscherRecord r : this) {
             if(r instanceof EscherContainerRecord) {
                 containers.add((EscherContainerRecord) r);
             }
@@ -228,9 +234,7 @@ public final class EscherContainerRecord extends EscherRecord {
     @Override
     public void display(PrintWriter w, int indent) {
         super.display(w, indent);
-        for (Iterator<EscherRecord> iterator = _childRecords.iterator(); iterator.hasNext();)
-        {
-            EscherRecord escherRecord = iterator.next();
+        for (EscherRecord escherRecord : this) {
             escherRecord.display(w, indent + 1);
         }
     }
@@ -252,8 +256,10 @@ public final class EscherContainerRecord extends EscherRecord {
      */
     public void addChildBefore(EscherRecord record, int insertBeforeRecordId) {
         int idx = 0;
-        for (EscherRecord rec : _childRecords) {
-            if(rec.getRecordId() == (short)insertBeforeRecordId) break;
+        for (EscherRecord rec : this) {
+            if(rec.getRecordId() == (short)insertBeforeRecordId) {
+                break;
+            }
             // TODO - keep looping? Do we expect multiple matches?
             idx++;
         }
@@ -271,10 +277,7 @@ public final class EscherContainerRecord extends EscherRecord {
             children.append( "  children: " + nl );
 
             int count = 0;
-            for ( Iterator<EscherRecord> iterator = _childRecords.iterator(); iterator
-                    .hasNext(); )
-            {
-                EscherRecord record = iterator.next();
+            for ( EscherRecord record : this ) {
                 children.append( "   Child " + count + ":" + nl );
                 String childResult = String.valueOf( record );
                 childResult = childResult.replaceAll( "\n", "\n    " );
@@ -298,22 +301,16 @@ public final class EscherContainerRecord extends EscherRecord {
     public String toXml(String tab) {
         StringBuilder builder = new StringBuilder();
         builder.append(tab).append(formatXmlRecordHeader(getRecordName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())));
-        for ( Iterator<EscherRecord> iterator = _childRecords.iterator(); iterator
-                .hasNext(); )
-        {
-            EscherRecord record = iterator.next();
+        for ( EscherRecord record : this ) {
             builder.append(record.toXml(tab+"\t"));
         }
         builder.append(tab).append("</").append(getRecordName()).append(">\n");
         return builder.toString();
     }
 
-    public <T extends EscherRecord> T getChildById( short recordId )
-    {
-        for ( EscherRecord childRecord : _childRecords )
-        {
-            if ( childRecord.getRecordId() == recordId )
-            {
+    public <T extends EscherRecord> T getChildById( short recordId ) {
+        for ( EscherRecord childRecord : this ) {
+            if ( childRecord.getRecordId() == recordId ) {
                 @SuppressWarnings( "unchecked" )
                 final T result = (T) childRecord;
                 return result;
@@ -329,9 +326,7 @@ public final class EscherContainerRecord extends EscherRecord {
      * @param out - list to store found records
      */
     public void getRecordsById(short recordId, List<EscherRecord> out){
-        Iterator<EscherRecord> iterator = _childRecords.iterator();
-        while (iterator.hasNext()) {
-            EscherRecord r = iterator.next();
+        for (EscherRecord r : this) {
             if(r instanceof EscherContainerRecord) {
                 EscherContainerRecord c = (EscherContainerRecord)r;
                 c.getRecordsById(recordId, out );
index 5465f0ff104dc1217eab2de5dde55cc65225d4d4..04e965d4414406c8d65ac06bd9d72dc811c2249c 100644 (file)
@@ -194,6 +194,7 @@ import org.apache.poi.hssf.record.pivottable.ViewSourceRecord;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.util.HexDump;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
@@ -251,12 +252,10 @@ public final class BiffViewer {
                 }
                 temp.add(record);
 
-                if (dumpInterpretedRecords) {
-                    for (String header : recListener.getRecentHeaders()) {
-                        ps.println(header);
-                    }
-                    ps.print(record.toString());
+                for (String header : recListener.getRecentHeaders()) {
+                    ps.println(header);
                 }
+                ps.print(record.toString());
             } else {
                 recStream.readRemainder();
             }
@@ -560,33 +559,26 @@ public final class BiffViewer {
                        pw = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
                }
 
+               NPOIFSFileSystem fs = null;
+               InputStream is = null;
         try {
-            NPOIFSFileSystem fs = new NPOIFSFileSystem(cmdArgs.getFile(), true);
-            try {
-                InputStream is = getPOIFSInputStream(fs);
+            fs = new NPOIFSFileSystem(cmdArgs.getFile(), true);
+            is = getPOIFSInputStream(fs);
 
-                try {
-                    if (cmdArgs.shouldOutputRawHexOnly()) {
-                        int size = is.available();
-                        byte[] data = new byte[size];
-
-                        is.read(data);
-                        HexDump.dump(data, 0, System.out, 0);
-                    } else {
-                        boolean dumpInterpretedRecords = cmdArgs.shouldDumpRecordInterpretations();
-                        boolean dumpHex = cmdArgs.shouldDumpBiffHex();
-                        boolean zeroAlignHexDump = dumpInterpretedRecords;  // TODO - fix non-zeroAlign
-                        runBiffViewer(pw, is, dumpInterpretedRecords, dumpHex, zeroAlignHexDump,
-                                cmdArgs.suppressHeader());
-                    }
-                } finally {
-                    is.close();
-                }
-            } finally {
-                fs.close();
+            if (cmdArgs.shouldOutputRawHexOnly()) {
+                byte[] data = IOUtils.toByteArray(is);
+                HexDump.dump(data, 0, System.out, 0);
+            } else {
+                boolean dumpInterpretedRecords = cmdArgs.shouldDumpRecordInterpretations();
+                boolean dumpHex = cmdArgs.shouldDumpBiffHex();
+                boolean zeroAlignHexDump = dumpInterpretedRecords;  // TODO - fix non-zeroAlign
+                runBiffViewer(pw, is, dumpInterpretedRecords, dumpHex, zeroAlignHexDump,
+                        cmdArgs.suppressHeader());
             }
         } finally {
-            pw.close();
+            IOUtils.closeQuietly(is);
+            IOUtils.closeQuietly(fs);
+            IOUtils.closeQuietly(pw);
         }
        }
 
index 8cc1d96bd8068f86b16b9a07dfa99caa578ad948..3d6bc3515cefddd2530fd1389f8f56a5e508781e 100644 (file)
@@ -82,28 +82,18 @@ public class OldExcelExtractor implements Closeable {
             return;
         } catch (OldExcelFormatException e) {
             // will be handled by workaround below
-            if (poifs != null) {
-                poifs.close();
-            }
         } catch (NotOLE2FileException e) {
             // will be handled by workaround below
-            if (poifs != null) {
-                poifs.close();
-            }
         } catch (IOException e) {
             // ensure streams are closed correctly
-            if (poifs != null) {
-                poifs.close();
-            }
-
             throw e;
         } catch (RuntimeException e) {
             // ensure streams are closed correctly
-            if (poifs != null) {
-                poifs.close();
-            }
-
             throw e;
+        } finally {
+            if (toClose == null) {
+                IOUtils.closeQuietly(poifs);
+            }
         }
 
         @SuppressWarnings("resource")
index 3a5fc1ef553af5b3c13a7d573bd1431afd9bac2e..843f142289420f4668847f05f5a627ffc4a342eb 100644 (file)
@@ -110,6 +110,7 @@ import org.apache.poi.util.Internal;
 import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
+import org.apache.poi.util.RecordFormatException;
 
 /**
  * Low level model implementation of a Workbook.  Provides creational methods
@@ -2292,8 +2293,7 @@ public final class InternalWorkbook {
 
                 EscherDggRecord dgg = null;
                 EscherContainerRecord bStore = null;
-                for(Iterator<EscherRecord> it = cr.getChildIterator(); it.hasNext();) {
-                    EscherRecord er = it.next();
+                for(EscherRecord er : cr) {
                     if(er instanceof EscherDggRecord) {
                         dgg = (EscherDggRecord)er;
                     } else if (er.getRecordId() == EscherContainerRecord.BSTORE_CONTAINER) {
@@ -2590,8 +2590,7 @@ public final class InternalWorkbook {
             dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
 
             EscherDgRecord dg = null;
-            for(Iterator<EscherRecord> it = escherContainer.getChildIterator(); it.hasNext();) {
-                EscherRecord er = it.next();
+            for(EscherRecord er : escherContainer) {
                 if(er instanceof EscherDgRecord) {
                     dg = (EscherDgRecord)er;
                     //update id of the drawing in the cloned sheet
@@ -2604,6 +2603,9 @@ public final class InternalWorkbook {
                         for(EscherRecord shapeChildRecord : shapeContainer.getChildRecords()) {
                             int recordId = shapeChildRecord.getRecordId();
                             if (recordId == EscherSpRecord.RECORD_ID){
+                                if (dg == null) {
+                                    throw new RecordFormatException("EscherDgRecord wasn't set/processed before.");
+                                }
                                 EscherSpRecord sp = (EscherSpRecord)shapeChildRecord;
                                 int shapeId = drawingManager.allocateShapeId((short)dgId, dg);
                                 //allocateShapeId increments the number of shapes. roll back to the previous value
index 4cefdee1027922ddb05e34f97ef6c20d40fd4c3e..9e758782d213add24bdec6a2e7492636e31393c6 100644 (file)
@@ -748,7 +748,7 @@ public class UnicodeString implements Comparable<UnicodeString> {
           }
         }
 
-        if (extendedDataSize > 0) {
+        if (extendedDataSize > 0 && field_5_ext_rst != null) {
            field_5_ext_rst.serialize(out);
         }
     }
index 772ee5821d30fdbf5182b5d18642db5fab7b493f..5135078c00479b15e3ce512e843bd638e372b6ea 100644 (file)
 \r
 package org.apache.poi.hssf.usermodel;\r
 \r
-import org.apache.poi.ddf.*;\r
-import org.apache.poi.hssf.record.*;\r
-import org.apache.poi.poifs.filesystem.DirectoryNode;\r
-\r
-import java.util.Iterator;\r
 import java.util.List;\r
 import java.util.Map;\r
 \r
+import org.apache.poi.ddf.EscherClientDataRecord;\r
+import org.apache.poi.ddf.EscherContainerRecord;\r
+import org.apache.poi.ddf.EscherOptRecord;\r
+import org.apache.poi.ddf.EscherProperties;\r
+import org.apache.poi.ddf.EscherProperty;\r
+import org.apache.poi.ddf.EscherRecord;\r
+import org.apache.poi.ddf.EscherTextboxRecord;\r
+import org.apache.poi.hssf.record.CommonObjectDataSubRecord;\r
+import org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord;\r
+import org.apache.poi.hssf.record.EscherAggregate;\r
+import org.apache.poi.hssf.record.ObjRecord;\r
+import org.apache.poi.hssf.record.Record;\r
+import org.apache.poi.hssf.record.SubRecord;\r
+import org.apache.poi.hssf.record.TextObjectRecord;\r
+import org.apache.poi.poifs.filesystem.DirectoryNode;\r
+import org.apache.poi.util.RecordFormatException;\r
+\r
 /**\r
  * Factory class for producing Excel Shapes from Escher records\r
  */\r
@@ -58,7 +70,7 @@ public class HSSFShapeFactory {
             ObjRecord objRecord = null;\r
             TextObjectRecord txtRecord = null;\r
 \r
-            for (EscherRecord record : container.getChildRecords()) {\r
+            for (EscherRecord record : container) {\r
                 switch (record.getRecordId()) {\r
                     case EscherClientDataRecord.RECORD_ID:\r
                         objRecord = (ObjRecord) shapeToObj.get(record);\r
@@ -70,6 +82,9 @@ public class HSSFShapeFactory {
                         break;\r
                 }\r
             }\r
+            if (objRecord == null) {\r
+                throw new RecordFormatException("EscherClientDataRecord can't be found.");\r
+            }\r
             if (isEmbeddedObject(objRecord)) {\r
                 HSSFObjectData objectData = new HSSFObjectData(container, objRecord, root);\r
                 out.addShape(objectData);\r
@@ -117,9 +132,7 @@ public class HSSFShapeFactory {
     }\r
 \r
     private static boolean isEmbeddedObject(ObjRecord obj) {\r
-        Iterator<SubRecord> subRecordIter = obj.getSubRecords().iterator();\r
-        while (subRecordIter.hasNext()) {\r
-            SubRecord sub = subRecordIter.next();\r
+        for (SubRecord sub : obj.getSubRecords()) {\r
             if (sub instanceof EmbeddedObjectRefSubRecord) {\r
                 return true;\r
             }\r
index 471856a9e5d7658e150b3fe12a637019abb84fbf..4e5f2809515a697a4fb0d75a261db14d93be30ac 100644 (file)
@@ -1688,7 +1688,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
                 // Need to walk backward to find the last non-blank row
                 // NOTE: n is always negative here
                 _lastrow = Math.min(endRow + n, SpreadsheetVersion.EXCEL97.getLastRowIndex());
-                for (int i = endRow - 1; i > endRow + n; i++) {
+                for (int i = endRow - 1; i > endRow + n; i--) {
                     if (getRow(i) != null) {
                         _lastrow = i;
                         break;
index 0cdb1f6273c33c2feda3de7450f42e38d73e4a58..d655e5a4fee4c600b8d306d8242107663aa7a17e 100644 (file)
@@ -71,17 +71,14 @@ public final class PPDrawingGroup extends RecordAtom {
 
     public void writeOut(OutputStream out) throws IOException {
         ByteArrayOutputStream bout = new ByteArrayOutputStream();
-        Iterator<EscherRecord> iter = dggContainer.getChildIterator();
-        while (iter.hasNext()) {
-               EscherRecord r = iter.next();
+        for (EscherRecord r : dggContainer) {
             if (r.getRecordId() == EscherContainerRecord.BSTORE_CONTAINER){
                 EscherContainerRecord bstore = (EscherContainerRecord)r;
 
                 ByteArrayOutputStream b2 = new ByteArrayOutputStream();
-                for (Iterator<EscherRecord> it= bstore.getChildIterator(); it.hasNext();) {
-                    EscherBSERecord bse = (EscherBSERecord)it.next();
+                for (EscherRecord br : bstore) {
                     byte[] b = new byte[36+8];
-                    bse.serialize(0, b);
+                    br.serialize(0, b);
                     b2.write(b);
                 }
                 byte[] bstorehead = new byte[8];
@@ -120,8 +117,7 @@ public final class PPDrawingGroup extends RecordAtom {
 
     public EscherDggRecord getEscherDggRecord(){
         if(dgg == null){
-            for(Iterator<EscherRecord> it = dggContainer.getChildIterator(); it.hasNext();){
-                EscherRecord r = it.next();
+            for(EscherRecord r : dggContainer){
                 if(r instanceof EscherDggRecord){
                     dgg = (EscherDggRecord)r;
                     break;
index bd90edfec42db3efe7829a871bd9dc32406aa4e7..3d4d57fbdb45492fcb9668808812ffd157657096 100644 (file)
@@ -272,17 +272,17 @@ implements HSLFShapeContainer, GroupShape<HSLFShape,HSLFTextParagraph> {
 
     @Override
     public List<HSLFShape> getShapes() {
-        // Out escher container record should contain several
-        //  SpContainers, the first of which is the group shape itself
-        Iterator<EscherRecord> iter = getSpContainer().getChildIterator();
-
-        // Don't include the first SpContainer, it is always NotPrimitive
-        if (iter.hasNext()) {
-            iter.next();
-        }
+        // Our escher container record should contain several
+        // SpContainers, the first of which is the group shape itself
         List<HSLFShape> shapeList = new ArrayList<HSLFShape>();
-        while (iter.hasNext()) {
-            EscherRecord r = iter.next();
+        boolean isFirst = true;
+        for (EscherRecord r : getSpContainer()) {
+            if (isFirst) {
+                // Don't include the first SpContainer, it is always NotPrimitive
+                isFirst = false;
+                continue;
+            }
+            
             if(r instanceof EscherContainerRecord) {
                 // Create the Shape for it
                 EscherContainerRecord container = (EscherContainerRecord)r;
index 72042769d1d116e9faf44fcc218b422c7e8b3b57..5bfd3bbc9cf3d04538e11027eabeebab5059b92d 100644 (file)
@@ -151,8 +151,7 @@ public abstract class HSLFSheet implements HSLFShapeContainer, Sheet<HSLFShape,H
         EscherContainerRecord dg = ppdrawing.getDgContainer();
         EscherContainerRecord spgr = null;
 
-        for (Iterator<EscherRecord> it = dg.getChildIterator(); it.hasNext();) {
-            EscherRecord rec = it.next();
+        for (EscherRecord rec : dg) {
             if (rec.getRecordId() == EscherContainerRecord.SPGR_CONTAINER) {
                 spgr = (EscherContainerRecord) rec;
                 break;
@@ -163,13 +162,15 @@ public abstract class HSLFSheet implements HSLFShapeContainer, Sheet<HSLFShape,H
         }
 
         List<HSLFShape> shapeList = new ArrayList<HSLFShape>();
-        Iterator<EscherRecord> it = spgr.getChildIterator();
-        if (it.hasNext()) {
-            // skip first item
-            it.next();
-        }
-        for (; it.hasNext();) {
-            EscherContainerRecord sp = (EscherContainerRecord) it.next();
+        boolean isFirst = true;
+        for (EscherRecord r : spgr) {
+            if (isFirst) {
+                // skip first item
+                isFirst = false;
+                continue;
+            }
+
+            EscherContainerRecord sp = (EscherContainerRecord)r;
             HSLFShape sh = HSLFShapeFactory.createShape(sp, null);
             sh.setSheet(this);
             
index b20af62ec9833bce7783694396047b6e87be63e2..1251904b21f79a54a461f384cf7c9ffeb59af2f3 100644 (file)
@@ -376,14 +376,8 @@ public class HSLFSlideShowEncrypted implements Closeable {
         } catch (Exception e) {
             throw new EncryptedPowerPointFileException(e);
         } finally {
-            try {
-                if (ccos != null) {
-                    ccos.close();
-                }
-                los.close();
-            } catch (IOException e) {
-                throw new EncryptedPowerPointFileException(e);
-            }
+            IOUtils.closeQuietly(ccos);
+            IOUtils.closeQuietly(los);
         }
     }
 
index 4cb3a310c353333ffd1aaa8db54faefdae6bc46d..60232d50a7176cd4d428e9c80f52937f5dbc9d2c 100644 (file)
@@ -980,7 +980,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
             }\r
         }\r
 \r
-        if (lastPTPC == null || lastRTPC == null || ptpc == null || rtpc == null) {\r
+        if (lastPTPC == null || lastRTPC == null || ptpc == null || rtpc == null) { // NOSONAR\r
             throw new HSLFException("Not all TextPropCollection could be determined.");\r
         }\r
         \r
index a919b047f26d4ee98fb9c42558b2b7426db27b72..1b67e52ff9e9688fa1be3c30904e046e9bc8acc3 100644 (file)
@@ -227,49 +227,47 @@ public final class HSSFChart {
 
                        if(r instanceof ChartRecord) {
                                lastSeries = null;
-                               
                                lastChart = new HSSFChart(sheet,(ChartRecord)r);
                                charts.add(lastChart);
-                       } else if(r instanceof LegendRecord) {
+            } else if (r instanceof LinkedDataRecord) {
+                LinkedDataRecord linkedDataRecord = (LinkedDataRecord) r;
+                if (lastSeries != null) {
+                    lastSeries.insertData(linkedDataRecord);
+                }
+                       }
+            
+            if (lastChart == null) {
+                continue;
+            }
+            
+            if (r instanceof LegendRecord) {
                                lastChart.legendRecord = (LegendRecord)r;
                        } else if(r instanceof SeriesRecord) {
                                HSSFSeries series = new HSSFSeries( (SeriesRecord)r );
                                lastChart.series.add(series);
                                lastSeries = series;
                        } else if(r instanceof ChartTitleFormatRecord) {
-                               lastChart.chartTitleFormat =
-                                       (ChartTitleFormatRecord)r;
+                               lastChart.chartTitleFormat = (ChartTitleFormatRecord)r;
                        } else if(r instanceof SeriesTextRecord) {
-                               // Applies to a series, unless we've seen
-                               //  a legend already
+                               // Applies to a series, unless we've seen a legend already
                                SeriesTextRecord str = (SeriesTextRecord)r;
-                               if(lastChart.legendRecord == null &&
-                                               lastChart.series.size() > 0) {
+                               if(lastChart.legendRecord == null && lastChart.series.size() > 0) {
                                        HSSFSeries series = lastChart.series.get(lastChart.series.size()-1);
                                        series.seriesTitleText = str;
                                } else {
                                        lastChart.chartTitleText = str;
                                }
-                       } else if (r instanceof LinkedDataRecord) {
-                               LinkedDataRecord linkedDataRecord = (LinkedDataRecord) r;
-                               if (lastSeries != null) {
-                                       lastSeries.insertData(linkedDataRecord);
-                               }
                        } else if(r instanceof ValueRangeRecord){
                                lastChart.valueRanges.add((ValueRangeRecord)r);
                        } else if (r instanceof Record) {
-                               if (lastChart != null)
-                               {
-                                       Record record = (Record) r;
-                                       for (HSSFChartType type : HSSFChartType.values()) {
-                                               if (type == HSSFChartType.Unknown)
-                                               {
-                                                       continue;
-                                               }
-                                               if (record.getSid() == type.getSid()) {
-                                                       lastChart.type = type ;
-                                                       break;
-                                               }
+                               Record record = (Record) r;
+                               for (HSSFChartType type : HSSFChartType.values()) {
+                                       if (type == HSSFChartType.Unknown) {
+                                               continue;
+                                       }
+                                       if (record.getSid() == type.getSid()) {
+                                               lastChart.type = type;
+                                               break;
                                        }
                                }
                        }