From d136eaa77889159fb88f9761aaeb469f45398735 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Mon, 21 May 2018 23:17:57 +0000 Subject: sonar fixes - null dereference git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1831992 13f79535-47bb-0310-9956-ffa450edef68 --- .../usermodel/examples/AddDimensionedImage.java | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/examples') diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java index 61629d5c44..bee33a250d 100644 --- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java +++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java @@ -279,14 +279,19 @@ public class AddDimensionedImage { // The first two parameters are not used currently but could be if the // need arose to extend the functionality of this code by adding the // ability to specify that a clear 'border' be placed around the image. - anchor = new HSSFClientAnchor(0, - 0, - colClientAnchorDetail.getInset(), - rowClientAnchorDetail.getInset(), - (short)colClientAnchorDetail.getFromIndex(), - rowClientAnchorDetail.getFromIndex(), - (short)colClientAnchorDetail.getToIndex(), - rowClientAnchorDetail.getToIndex()); + int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0; + short col1 = 0, col2 = 0, row1 = 0, row2 = 0; + if (colClientAnchorDetail != null) { + dx2 = colClientAnchorDetail.getInset(); + col1 = (short)colClientAnchorDetail.getFromIndex(); + col2 = (short)colClientAnchorDetail.getToIndex(); + } + if (rowClientAnchorDetail != null) { + dy2 = rowClientAnchorDetail.getInset(); + row1 = (short)rowClientAnchorDetail.getFromIndex(); + row2 = (short)rowClientAnchorDetail.getToIndex(); + } + anchor = new HSSFClientAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2); // For now, set the anchor type to do not move or resize the // image as the size of the row/column is adjusted. This could easilly -- cgit v1.2.3