FindBugs fix

- fixed/checked various null pointer related entries
- see http://findbugs.sourceforge.net/bugDescriptions.html#NP_NULL_PARAM_DEREF
- ... NP_NULL_ON_SOME_PATH, NP_NULL_ON_SOME_PATH_EXCEPTION


git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1568789 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2014-02-16 16:30:24 +00:00
parent 929f938b3c
commit 2a14920cdd
13 changed files with 43 additions and 20 deletions

View File

@ -66,10 +66,10 @@ public class FontDetails
public int getCharWidth( char c )
{
Integer widthInteger = charWidths.get(Character.valueOf(c));
if (widthInteger == null && c != 'W') {
return getCharWidth('W');
if (widthInteger == null) {
return 'W' == c ? 0 : getCharWidth('W');
}
return widthInteger.intValue();
return widthInteger;
}
public void addChars( char[] characters, int[] widths )

View File

@ -25,7 +25,7 @@ public class BaseNumberUtils {
public static double convertToDecimal(String value, int base, int maxNumberOfPlaces) throws IllegalArgumentException {
if (value != null && value.length() == 0) {
if (value == null || value.length() == 0) {
return 0.0;
}

View File

@ -36,7 +36,7 @@ public final class DigitalCertificatePart extends PackagePart {
public DigitalCertificatePart() throws InvalidFormatException{
super(null, null, new ContentType(""));
// Review constructor
// TODO: Review constructor
}
@Override

View File

@ -30,6 +30,7 @@ public final class PackageDigitalSignature extends PackagePart {
public PackageDigitalSignature() throws InvalidFormatException {
super(null, null, new ContentType(""));
// TODO: Review constructor
}
@Override

View File

@ -71,7 +71,21 @@ import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookView;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookViews;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedNames;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheets;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookProtection;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCalcMode;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STSheetState;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument;
/**
* High level representation of a SpreadsheetML workbook. This is the first object most users
@ -1240,6 +1254,8 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
// YK: Mimic Excel and silently truncate sheet names longer than 31 characters
if(sheetname != null && sheetname.length() > 31) sheetname = sheetname.substring(0, 31);
WorkbookUtil.validateSheetName(sheetname);
// findbugs fix - validateSheetName has already checked for null value
assert(sheetname != null);
if (containsSheet(sheetname, sheetIndex ))
throw new IllegalArgumentException( "The workbook already contains a sheet of this name" );

View File

@ -55,11 +55,13 @@ public class ColumnHelper {
CTCols aggregateCols = CTCols.Factory.newInstance();
List<CTCols> colsList = worksheet.getColsList();
if (colsList != null) {
for (CTCols cols : colsList) {
for (CTCol col : cols.getColList()) {
cloneCol(aggregateCols, col);
}
if (colsList == null || colsList.isEmpty()) {
return;
}
for (CTCols cols : colsList) {
for (CTCol col : cols.getColList()) {
cloneCol(aggregateCols, col);
}
}

View File

@ -65,11 +65,11 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.NumberingDocument;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CommentsDocument;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.EndnotesDocument;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.FootnotesDocument;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.NumberingDocument;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
@ -1156,7 +1156,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
throw new POIXMLException(e);
} finally {
try {
out.close();
if (out != null) out.close();
} catch (IOException e) {
// ignore
}

View File

@ -257,7 +257,7 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo
throw new POIXMLException(e);
} finally {
try {
out.close();
if (out != null) out.close();
} catch (IOException e) {
// ignore
}

View File

@ -41,7 +41,6 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRunTrackChange;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtContentRun;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtRun;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSimpleField;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSmartTagRun;
@ -472,8 +471,11 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents {
*/
public void setBorderTop(Borders border) {
CTPBdr ct = getCTPBrd(true);
if (ct == null) {
throw new RuntimeException("invalid paragraph state");
}
CTBorder pr = (ct != null && ct.isSetTop()) ? ct.getTop() : ct.addNewTop();
CTBorder pr = (ct.isSetTop()) ? ct.getTop() : ct.addNewTop();
if (border.getValue() == Borders.NONE.getValue())
ct.unsetTop();
else

View File

@ -160,7 +160,7 @@ public class XWPFPictureData extends POIXMLDocumentPart {
throw new POIXMLException(e);
} finally {
try {
is.close();
if (is != null) is.close();
} catch (IOException e) {
throw new POIXMLException(e);
}

View File

@ -29,8 +29,8 @@ import org.apache.poi.hslf.model.textproperties.ParagraphFlagsTextProp;
import org.apache.poi.hslf.model.textproperties.TextProp;
import org.apache.poi.hslf.model.textproperties.TextPropCollection;
import org.apache.poi.hslf.record.ColorSchemeAtom;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
/**
@ -325,6 +325,7 @@ public final class RichTextRun {
// paragraphStyle will now be defined
}
assert(paragraphStyle!=null);
TextProp tp = fetchOrAddTextProp(paragraphStyle, propName);
tp.setValue(val);
}
@ -340,6 +341,7 @@ public final class RichTextRun {
// characterStyle will now be defined
}
assert(characterStyle!=null);
TextProp tp = fetchOrAddTextProp(characterStyle, propName);
tp.setValue(val);
}

View File

@ -97,7 +97,7 @@ public final class SprmUtils
break;
default:
//should never happen
break;
throw new RuntimeException("Invalid sprm type");
}
LittleEndian.putShort(sprm, 0, instruction);
list.add(sprm);

View File

@ -62,7 +62,7 @@ public final class SectionProperties extends SEPAbstractType
{
continue;
}
if ( !obj1.equals( obj2 ) )
if ( obj1 == null || obj2 == null || !obj1.equals( obj2 ) )
{
return false;
}