]> source.dussan.org Git - poi.git/commitdiff
sonar fixes
authorAndreas Beeker <kiwiwings@apache.org>
Wed, 23 May 2018 22:29:40 +0000 (22:29 +0000)
committerAndreas Beeker <kiwiwings@apache.org>
Wed, 23 May 2018 22:29:40 +0000 (22:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1832131 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xddf/usermodel/chart/XDDFChart.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFGraphicFrame.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFNotes.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableCell.java
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTextRun.java

index 08b32947e48a09e611f8f26ebf5dc110bbe0c865..26428593bffed1181b09b37cfc9b2c93d392fb89 100644 (file)
@@ -74,7 +74,6 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumns;
 
 @Beta
 public abstract class XDDFChart extends POIXMLDocumentPart {
-
     /**
      * Underlying workbook
      */
@@ -456,6 +455,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart {
                 && chartWorkbookRelation != null
                 && chartFactory != null) {
                 worksheetPart = createWorksheetPart(chartRelation, chartWorkbookRelation, chartFactory);
+            } else {
+                throw new InvalidFormatException("unable to determine chart relations");
             }
         }
         try (OutputStream xlsOut = worksheetPart.getOutputStream()) {
@@ -610,7 +611,8 @@ public abstract class XDDFChart extends POIXMLDocumentPart {
      * @since POI 4.0.0
      */
     public String formatRange(CellRangeAddress range) {
-        return range.formatAsString(getSheet().getSheetName(), true);
+        final XSSFSheet sheet = getSheet();
+        return (sheet == null) ? null : range.formatAsString(sheet.getSheetName(), true);
     }
 
     /**
index 35da6bf558cbc84e4b8bbc1eb5ad310a6952fb71..5b6c07954ea4b50e62bd9b6970411652775ff95c 100644 (file)
@@ -87,7 +87,8 @@ public class XSLFGraphicFrame extends XSLFShape implements GraphicalFrame<XSLFSh
 
 
     static XSLFGraphicFrame create(CTGraphicalObjectFrame shape, XSLFSheet sheet){
-        switch (getUri(shape)) {
+        final String uri = getUri(shape);
+        switch (uri == null ? "" : uri) {
         case XSLFTable.TABLE_URI:
             return new XSLFTable(shape, sheet);
         case XSLFObjectShape.OLE_URI:
index 6eee234f78ea6eb37dbdf7b1d4342985f053e44d..9203b06f40abb01baf8fb419994baf02bc2d977a 100644 (file)
@@ -82,7 +82,8 @@ implements Notes<XSLFShape,XSLFTextParagraph> {
 
     @Override
     public XSLFTheme getTheme(){
-       return getMasterSheet().getTheme();
+        final XSLFNotesMaster m = getMasterSheet();
+       return (m != null) ? m.getTheme() : null;
     }
 
     @Override
index 589f84e91821986406e7e2c38c7fec55c51bac4b..52cbc750ae5b57dae876efdfb507e03bec0927df 100644 (file)
@@ -258,12 +258,19 @@ public class XSLFTableCell extends XSLFTextShape implements TableCell<XSLFShape,
 
     @Override
     public void setBorderWidth(BorderEdge edge, double width) {
-        CTLineProperties ln = getCTLine(edge, true);
+        final CTLineProperties ln = getCTLine(edge, true);
+        if (ln == null) {
+            return;
+        }
         ln.setW(Units.toEMU(width));
     }
 
     private CTLineProperties setBorderDefaults(BorderEdge edge) {
-        CTLineProperties ln = getCTLine(edge, true);
+        final CTLineProperties ln = getCTLine(edge, true);
+        if (ln == null) {
+            return null;
+        }
+
         if (ln.isSetNoFill()) {
             ln.unsetNoFill();
         }
index 5646fd40e21e564aafe7664c426cece47e61f0c3..40afebf051fc8b241991b80da77248ea8fd1c4f4 100644 (file)
@@ -605,6 +605,9 @@ public class XSLFTextRun implements TextRun {
 
         void copyFrom(FontInfo fontInfo) {
             CTTextFont tf = getXmlObject(true);
+            if (tf == null) {
+                return;
+            }
             setTypeface(fontInfo.getTypeface());
             setCharset(fontInfo.getCharset());
             FontPitch pitch = fontInfo.getPitch();
@@ -638,7 +641,10 @@ public class XSLFTextRun implements TextRun {
         @Override
         public void setTypeface(String typeface) {
             if (typeface != null) {
-                getXmlObject(true).setTypeface(typeface);
+                final CTTextFont tf = getXmlObject(true);
+                if (tf != null) {
+                    tf.setTypeface(typeface);
+                }
                 return;
             }
             
@@ -681,6 +687,9 @@ public class XSLFTextRun implements TextRun {
         @Override
         public void setCharset(FontCharset charset) {
             CTTextFont tf = getXmlObject(true);
+            if (tf == null) {
+                return;
+            }
             if (charset != null) {
                 tf.setCharset((byte)charset.getNativeId());
             } else {
@@ -699,7 +708,7 @@ public class XSLFTextRun implements TextRun {
         @Override
         public void setFamily(FontFamily family) {
             CTTextFont tf = getXmlObject(true);
-            if (family == null && !tf.isSetPitchFamily()) {
+            if (tf == null || (family == null && !tf.isSetPitchFamily())) {
                 return;
             }
             FontPitch pitch = (tf.isSetPitchFamily())
@@ -718,7 +727,7 @@ public class XSLFTextRun implements TextRun {
         @Override
         public void setPitch(FontPitch pitch) {
             CTTextFont tf = getXmlObject(true);
-            if (pitch == null && !tf.isSetPitchFamily()) {
+            if (tf == null || (pitch == null && !tf.isSetPitchFamily())) {
                 return;
             }
             FontFamily family = (tf.isSetPitchFamily())