mirror of https://github.com/apache/poi.git
fix some cases where iterator usage does not check hasNext
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1855480 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7f12edf416
commit
126606c838
|
@ -59,7 +59,7 @@ public class ImageUtils {
|
|||
*
|
||||
* @return image dimension in pixels
|
||||
*/
|
||||
public static Dimension getImageDimension(InputStream is, int type){
|
||||
public static Dimension getImageDimension(InputStream is, int type) {
|
||||
Dimension size = new Dimension();
|
||||
|
||||
switch (type){
|
||||
|
@ -70,9 +70,9 @@ public class ImageUtils {
|
|||
case Workbook.PICTURE_TYPE_DIB:
|
||||
try {
|
||||
//read the image using javax.imageio.*
|
||||
ImageInputStream iis = ImageIO.createImageInputStream( is );
|
||||
try {
|
||||
try (ImageInputStream iis = ImageIO.createImageInputStream(is)) {
|
||||
Iterator<ImageReader> i = ImageIO.getImageReaders( iis );
|
||||
if (i.hasNext()) {
|
||||
ImageReader r = i.next();
|
||||
try {
|
||||
r.setInput( iis );
|
||||
|
@ -90,8 +90,9 @@ public class ImageUtils {
|
|||
} finally {
|
||||
r.dispose();
|
||||
}
|
||||
} finally {
|
||||
iis.close();
|
||||
} else {
|
||||
logger.log(POILogger.WARN, "ImageIO found no images");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -98,7 +98,7 @@ public class GeometrySection extends XDGFSection {
|
|||
Iterator<GeometryRow> rows = getCombinedRows().iterator();
|
||||
|
||||
// special cases
|
||||
GeometryRow first = rows.next();
|
||||
GeometryRow first = rows.hasNext() ? rows.next() : null;
|
||||
|
||||
if (first instanceof Ellipse) {
|
||||
return ((Ellipse)first).getPath();
|
||||
|
|
|
@ -1220,7 +1220,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText
|
|||
assert(!paragraphs.isEmpty() && !paragraphs.get(0).getTextRuns().isEmpty());
|
||||
|
||||
Iterator<HSLFTextParagraph> paraIter = paragraphs.iterator();
|
||||
HSLFTextParagraph htp = paraIter.next(); // keep first
|
||||
HSLFTextParagraph htp = paraIter.hasNext() ? paraIter.next() : null; // keep first
|
||||
assert (htp != null);
|
||||
while (paraIter.hasNext()) {
|
||||
paraIter.next();
|
||||
|
|
Loading…
Reference in New Issue