Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 2a14920cdd778220c21644dfbd82a3789fdbf89f 1 parent 929f938
Andreas Beeker authored
View
6 src/java/org/apache/poi/hssf/usermodel/FontDetails.java
@@ -66,10 +66,10 @@ public void addChar( char c, int width )
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
2  src/java/org/apache/poi/ss/formula/functions/BaseNumberUtils.java
@@ -25,7 +25,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
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
2  src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalCertificatePart.java
@@ -36,7 +36,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
public DigitalCertificatePart() throws InvalidFormatException{
super(null, null, new ContentType(""));
- // Review constructor
+ // TODO: Review constructor
}
@Override
View
1  src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignature.java
@@ -30,6 +30,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
public PackageDigitalSignature() throws InvalidFormatException {
super(null, null, new ContentType(""));
+ // TODO: Review constructor
}
@Override
View
18 src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -71,7 +71,21 @@ Licensed to the Apache Software Foundation (ASF) under one or more
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 void setSheetName(int sheetIndex, String sheetname) {
// 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
12 src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/ColumnHelper.java
@@ -55,11 +55,13 @@ public void cleanColumns() {
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
4 src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
@@ -65,11 +65,11 @@ Licensed to the Apache Software Foundation (ASF) under one or more
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 String addPictureData(byte[] pictureData,int format) throws InvalidFormat
throw new POIXMLException(e);
} finally {
try {
- out.close();
+ if (out != null) out.close();
} catch (IOException e) {
// ignore
}
View
2  src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java
@@ -257,7 +257,7 @@ public String addPictureData(byte[] pictureData,int format) throws InvalidFormat
throw new POIXMLException(e);
} finally {
try {
- out.close();
+ if (out != null) out.close();
} catch (IOException e) {
// ignore
}
View
6 src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
@@ -41,7 +41,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
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 void setVerticalAlignment(TextAlignment valign) {
*/
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
2  src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
@@ -160,7 +160,7 @@ public Long getChecksum() {
throw new POIXMLException(e);
} finally {
try {
- is.close();
+ if (is != null) is.close();
} catch (IOException e) {
throw new POIXMLException(e);
}
View
4 src/scratchpad/src/org/apache/poi/hslf/usermodel/RichTextRun.java
@@ -29,8 +29,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more
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 void setParaTextPropVal(String propName, int val) {
// paragraphStyle will now be defined
}
+ assert(paragraphStyle!=null);
TextProp tp = fetchOrAddTextProp(paragraphStyle, propName);
tp.setValue(val);
}
@@ -340,6 +341,7 @@ public void setCharTextPropVal(String propName, int val) {
// characterStyle will now be defined
}
+ assert(characterStyle!=null);
TextProp tp = fetchOrAddTextProp(characterStyle, propName);
tp.setValue(val);
}
View
2  src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmUtils.java
@@ -97,7 +97,7 @@ public static int addSprm(short instruction, int param, byte[] varParam, List<by
break;
default:
//should never happen
- break;
+ throw new RuntimeException("Invalid sprm type");
}
LittleEndian.putShort(sprm, 0, instruction);
list.add(sprm);
View
2  src/scratchpad/src/org/apache/poi/hwpf/usermodel/SectionProperties.java
@@ -62,7 +62,7 @@ public boolean equals( Object obj )
{
continue;
}
- if ( !obj1.equals( obj2 ) )
+ if ( obj1 == null || obj2 == null || !obj1.equals( obj2 ) )
{
return false;
}
Please sign in to comment.
Something went wrong with that request. Please try again.