diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2020-04-20 22:01:54 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2020-04-20 22:01:54 +0000 |
commit | c8a5bdf22a0522b50d583c1033335cfc1dc19c43 (patch) | |
tree | a33cd95c22fcf8550226c7fed23531e0b645a813 /src/scratchpad | |
parent | 948d4a3574511368f2769c403c030fc69d4687f3 (diff) | |
download | poi-c8a5bdf22a0522b50d583c1033335cfc1dc19c43.tar.gz poi-c8a5bdf22a0522b50d583c1033335cfc1dc19c43.zip |
Sonar fix - "Add a "NoSuchElementException" for iteration beyond the end of the collection."
PPTX2PNG - handle ignoreParse/quite for file inputs too
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876768 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
-rw-r--r-- | src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java | 47 | ||||
-rw-r--r-- | src/scratchpad/src/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java | 4 |
2 files changed, 30 insertions, 21 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java b/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java index 32ec7c98c8..1b02478861 100644 --- a/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java +++ b/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java @@ -23,15 +23,22 @@ import java.io.IOException; import java.util.ArrayDeque; import java.util.Deque; import java.util.Iterator; +import java.util.NoSuchElementException; import javax.imageio.ImageIO; import org.apache.poi.hemf.record.emf.HemfComment; +import org.apache.poi.hemf.record.emf.HemfComment.EmfComment; +import org.apache.poi.hemf.record.emf.HemfComment.EmfCommentDataFormat; +import org.apache.poi.hemf.record.emf.HemfComment.EmfCommentDataGeneric; +import org.apache.poi.hemf.record.emf.HemfComment.EmfCommentDataMultiformats; +import org.apache.poi.hemf.record.emf.HemfComment.EmfCommentDataPlus; +import org.apache.poi.hemf.record.emf.HemfComment.EmfCommentDataWMF; import org.apache.poi.hemf.record.emf.HemfRecord; import org.apache.poi.hemf.record.emfplus.HemfPlusImage.EmfPlusBitmapDataType; import org.apache.poi.hemf.record.emfplus.HemfPlusImage.EmfPlusImage; -import org.apache.poi.hemf.record.emfplus.HemfPlusObject; import org.apache.poi.hemf.record.emfplus.HemfPlusObject.EmfPlusObject; +import org.apache.poi.hemf.record.emfplus.HemfPlusObject.EmfPlusObjectType; import org.apache.poi.hwmf.record.HwmfBitmapDib; import org.apache.poi.hwmf.record.HwmfFill; import org.apache.poi.hwmf.usermodel.HwmfEmbedded; @@ -70,26 +77,26 @@ public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> { iter = iterStack.peek(); while (iter.hasNext()) { Object obj = iter.next(); - if (obj instanceof HemfComment.EmfComment) { - HemfComment.EmfCommentData cd = ((HemfComment.EmfComment)obj).getCommentData(); + if (obj instanceof EmfComment) { + HemfComment.EmfCommentData cd = ((EmfComment)obj).getCommentData(); if ( - cd instanceof HemfComment.EmfCommentDataWMF || - cd instanceof HemfComment.EmfCommentDataGeneric + cd instanceof EmfCommentDataWMF || + cd instanceof EmfCommentDataGeneric ) { current = obj; return true; } - if (cd instanceof HemfComment.EmfCommentDataMultiformats) { - Iterator<?> iter2 = ((HemfComment.EmfCommentDataMultiformats)cd).getFormats().iterator(); + if (cd instanceof EmfCommentDataMultiformats) { + Iterator<?> iter2 = ((EmfCommentDataMultiformats)cd).getFormats().iterator(); if (iter2.hasNext()) { iterStack.push(iter2); continue; } } - if (cd instanceof HemfComment.EmfCommentDataPlus) { - Iterator<?> iter2 = ((HemfComment.EmfCommentDataPlus)cd).getRecords().iterator(); + if (cd instanceof EmfCommentDataPlus) { + Iterator<?> iter2 = ((EmfCommentDataPlus)cd).getRecords().iterator(); if (iter2.hasNext()) { iter = iter2; iterStack.push(iter2); @@ -98,12 +105,12 @@ public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> { } } - if (obj instanceof HemfComment.EmfCommentDataFormat) { + if (obj instanceof EmfCommentDataFormat) { current = obj; return true; } - if (obj instanceof EmfPlusObject && ((EmfPlusObject)obj).getObjectType() == HemfPlusObject.EmfPlusObjectType.IMAGE) { + if (obj instanceof EmfPlusObject && ((EmfPlusObject)obj).getObjectType() == EmfPlusObjectType.IMAGE) { current = obj; return true; } @@ -141,15 +148,15 @@ public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> { return emb; } - return null; + throw new NoSuchElementException("no further embedded wmf records found."); } private HwmfEmbedded checkEmfCommentDataWMF() { - if (!(current instanceof HemfComment.EmfCommentDataWMF && ((HemfComment.EmfComment)current).getCommentData() instanceof HemfComment.EmfCommentDataWMF)) { + if (!(current instanceof EmfComment && ((EmfComment)current).getCommentData() instanceof EmfCommentDataWMF)) { return null; } - HemfComment.EmfCommentDataWMF wmf = (HemfComment.EmfCommentDataWMF)((HemfComment.EmfComment)current).getCommentData(); + EmfCommentDataWMF wmf = (EmfCommentDataWMF)((EmfComment)current).getCommentData(); HwmfEmbedded emb = new HwmfEmbedded(); emb.setEmbeddedType(HwmfEmbeddedType.WMF); emb.setData(wmf.getWMFData()); @@ -158,10 +165,10 @@ public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> { } private HwmfEmbedded checkEmfCommentDataGeneric() { - if (!(current instanceof HemfComment.EmfComment && ((HemfComment.EmfComment)current).getCommentData() instanceof HemfComment.EmfCommentDataGeneric)) { + if (!(current instanceof EmfComment && ((EmfComment)current).getCommentData() instanceof EmfCommentDataGeneric)) { return null; } - HemfComment.EmfCommentDataGeneric cdg = (HemfComment.EmfCommentDataGeneric)((HemfComment.EmfComment)current).getCommentData(); + EmfCommentDataGeneric cdg = (EmfCommentDataGeneric)((EmfComment)current).getCommentData(); HwmfEmbedded emb = new HwmfEmbedded(); emb.setEmbeddedType(HwmfEmbeddedType.UNKNOWN); emb.setData(cdg.getPrivateData()); @@ -170,10 +177,10 @@ public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> { } private HwmfEmbedded checkEmfCommentDataFormat() { - if (!(current instanceof HemfComment.EmfCommentDataFormat)) { + if (!(current instanceof EmfCommentDataFormat)) { return null; } - HemfComment.EmfCommentDataFormat cdf = (HemfComment.EmfCommentDataFormat)current; + EmfCommentDataFormat cdf = (EmfCommentDataFormat)current; HwmfEmbedded emb = new HwmfEmbedded(); boolean isEmf = (cdf.getSignature() == HemfComment.EmfFormatSignature.ENHMETA_SIGNATURE); emb.setEmbeddedType(isEmf ? HwmfEmbeddedType.EMF : HwmfEmbeddedType.EPS); @@ -199,7 +206,7 @@ public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> { } EmfPlusObject epo = (EmfPlusObject)current; - assert(epo.getObjectType() == HemfPlusObject.EmfPlusObjectType.IMAGE); + assert(epo.getObjectType() == EmfPlusObjectType.IMAGE); EmfPlusImage img = epo.getObjectData(); assert(img.getImageDataType() != null); @@ -279,7 +286,7 @@ public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> { private HwmfEmbedded getEmfPlusImageData() { EmfPlusObject epo = (EmfPlusObject)current; - assert(epo.getObjectType() == HemfPlusObject.EmfPlusObjectType.IMAGE); + assert(epo.getObjectType() == EmfPlusObjectType.IMAGE); final int objectId = epo.getObjectId(); diff --git a/src/scratchpad/src/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java b/src/scratchpad/src/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java index 5d5b88ab33..19fda80509 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java @@ -22,6 +22,7 @@ import java.io.IOException; import java.util.ArrayDeque; import java.util.Deque; import java.util.Iterator; +import java.util.NoSuchElementException; import org.apache.poi.hwmf.record.HwmfEscape; import org.apache.poi.hwmf.record.HwmfEscape.EscapeFunction; @@ -85,7 +86,8 @@ public class HwmfEmbeddedIterator implements Iterator<HwmfEmbedded> { if ((emb = checkHwmfEscapeRecord()) != null) { return emb; } - return null; + + throw new NoSuchElementException("no further embedded emf records found."); } private HwmfEmbedded checkHwmfImageRecord() { |