aboutsummaryrefslogtreecommitdiffstats
path: root/src/scratchpad
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2020-04-14 19:07:24 +0000
committerAndreas Beeker <kiwiwings@apache.org>2020-04-14 19:07:24 +0000
commitd06de78703eb67738c8715e1dcdb1c967435c157 (patch)
treef656f977aebceae927c0080cde24c9b6b1af256e /src/scratchpad
parentfde6f81305eb7d8895916f998a25d4be03109b72 (diff)
downloadpoi-d06de78703eb67738c8715e1dcdb1c967435c157.tar.gz
poi-d06de78703eb67738c8715e1dcdb1c967435c157.zip
#64350 - Sonar fix - "Iterator.next()" methods should throw "NoSuchElementException"
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876525 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
-rw-r--r--src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java4
-rw-r--r--src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfRecordIterator.java4
-rw-r--r--src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusRecordIterator.java4
-rw-r--r--src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java31
4 files changed, 27 insertions, 16 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java b/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java
index 2e603fe261..228cfd285f 100644
--- a/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java
+++ b/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java
@@ -25,6 +25,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.function.Supplier;
import org.apache.poi.common.usermodel.GenericRecord;
@@ -172,6 +173,9 @@ public class HemfComment {
@Override
public EmfCommentData next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
EmfCommentData toReturn = currentRecord;
final boolean isEOF = (limit == -1 || leis.getReadIndex() >= startIdx+limit);
// (currentRecord instanceof HemfPlusMisc.EmfEof)
diff --git a/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfRecordIterator.java b/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfRecordIterator.java
index dc5a2e3d57..bbe930f4ac 100644
--- a/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfRecordIterator.java
+++ b/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfRecordIterator.java
@@ -19,6 +19,7 @@ package org.apache.poi.hemf.record.emf;
import java.io.IOException;
import java.util.Iterator;
+import java.util.NoSuchElementException;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.LittleEndianInputStream;
@@ -44,6 +45,9 @@ public class HemfRecordIterator implements Iterator<HemfRecord> {
@Override
public HemfRecord next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
HemfRecord toReturn = currentRecord;
currentRecord = (currentRecord instanceof HemfMisc.EmfEof) ? null : _next();
return toReturn;
diff --git a/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusRecordIterator.java b/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusRecordIterator.java
index d30ba5d79c..032ef0a86c 100644
--- a/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusRecordIterator.java
+++ b/src/scratchpad/src/org/apache/poi/hemf/record/emfplus/HemfPlusRecordIterator.java
@@ -19,6 +19,7 @@ package org.apache.poi.hemf.record.emfplus;
import java.io.IOException;
import java.util.Iterator;
+import java.util.NoSuchElementException;
import org.apache.poi.util.LittleEndianInputStream;
import org.apache.poi.util.RecordFormatException;
@@ -49,6 +50,9 @@ public class HemfPlusRecordIterator implements Iterator<HemfPlusRecord> {
@Override
public HemfPlusRecord next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
HemfPlusRecord toReturn = currentRecord;
// add the size for recordId/flags/recordSize/dataSize = 12 bytes
final boolean isEOF = (limit == -1 || (leis.getReadIndex()-startIdx)+12 > limit);
diff --git a/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java b/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java
index 0dff34f567..e11f005fe3 100644
--- a/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java
+++ b/src/scratchpad/src/org/apache/poi/hsmf/extractor/OutlookTextExtractor.java
@@ -16,6 +16,17 @@
==================================================================== */
package org.apache.poi.hsmf.extractor;
+import static org.apache.poi.util.StringUtil.startsWithIgnoreCase;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Locale;
+
import org.apache.poi.extractor.POIOLE2TextExtractor;
import org.apache.poi.hsmf.MAPIMessage;
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
@@ -24,16 +35,6 @@ import org.apache.poi.hsmf.exceptions.ChunkNotFoundException;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.Removal;
-import org.apache.poi.util.StringUtil.StringsIterator;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.SimpleDateFormat;
-import java.util.Locale;
-
-import static org.apache.poi.util.StringUtil.startsWithIgnoreCase;
/**
* A text extractor for HSMF (Outlook) .msg files.
@@ -90,13 +91,11 @@ public class OutlookTextExtractor extends POIOLE2TextExtractor {
msg.guess7BitEncoding();
// Off we go
- StringsIterator emails;
+ Iterator<String> emails;
try {
- emails = new StringsIterator(
- msg.getRecipientEmailAddressList()
- );
+ emails = Arrays.asList(msg.getRecipientEmailAddressList()).iterator();
} catch (ChunkNotFoundException e) {
- emails = new StringsIterator(new String[0]);
+ emails = Collections.emptyIterator();
}
try {
@@ -174,7 +173,7 @@ public class OutlookTextExtractor extends POIOLE2TextExtractor {
* of emails, and does its best to return something like
* "Nick <nick@example.com>; Jim <jim@example.com>"
*/
- protected void handleEmails(StringBuilder s, String type, String displayText, StringsIterator emails) {
+ protected void handleEmails(StringBuilder s, String type, String displayText, Iterator<String> emails) {
if (displayText == null || displayText.length() == 0) {
return;
}