You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2018/10/06 19:33:28 UTC

svn commit: r1843032 [3/3] - in /poi/branches/hemf: ./ jenkins/ maven/ sonar/ooxml/ src/examples/src/org/apache/poi/hssf/view/ src/examples/src/org/apache/poi/ss/examples/ src/examples/src/org/apache/poi/ss/examples/html/ src/examples/src/org/apache/po...

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBuiltinTableStyle.java Sat Oct  6 19:33:27 2018
@@ -18,7 +18,9 @@
 package org.apache.poi.xssf.usermodel;
 
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.StringWriter;
 import java.nio.charset.StandardCharsets;
 import java.util.EnumMap;
 import java.util.Map;
@@ -33,11 +35,13 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
-import org.w3c.dom.ls.DOMImplementationLS;
-import org.w3c.dom.ls.LSSerializer;
+
+import javax.xml.transform.*;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
 
 /**
- * Table style names defined in the OOXML spec.  
+ * Table style names defined in the OOXML spec.
  * The actual styling is defined in presetTableStyles.xml
  */
 public enum XSSFBuiltinTableStyle {
@@ -329,16 +333,16 @@ public enum XSSFBuiltinTableStyle {
     PivotStyleDark27,
     /***/
     PivotStyleDark28,
-   ;
-    
+    ;
+
     /**
      * Interestingly, this is initialized after the enum instances, so using an {@link EnumMap} works.
      */
     private static final Map<XSSFBuiltinTableStyle, TableStyle> styleMap = new EnumMap<>(XSSFBuiltinTableStyle.class);
-    
+
     private XSSFBuiltinTableStyle() {
     }
-    
+
     /**
      * @return built-in {@link TableStyle} definition
      */
@@ -346,9 +350,10 @@ public enum XSSFBuiltinTableStyle {
         init();
         return styleMap.get(this);
     }
-    
+
     /**
      * NOTE: only checks by name, not definition.
+     *
      * @param style
      * @return true if the style represents a built-in style, false if it is null or a custom style
      */
@@ -361,6 +366,7 @@ public enum XSSFBuiltinTableStyle {
             return false;
         }
     }
+
     /**
      * Only init once - thus the synchronized.  Lazy, after creating instances,
      * and only when a style is actually needed, to avoid overhead for uses
@@ -370,8 +376,8 @@ public enum XSSFBuiltinTableStyle {
      * during evaluation if desired.
      */
     public static synchronized void init() {
-        if (! styleMap.isEmpty()) return; 
-        
+        if (!styleMap.isEmpty()) return;
+
         /*
          * initialize map.  Every built-in has this format:
          * <styleName>
@@ -388,18 +394,18 @@ public enum XSSFBuiltinTableStyle {
             final InputStream is = XSSFBuiltinTableStyle.class.getResourceAsStream("presetTableStyles.xml");
             try {
                 final Document doc = DocumentHelper.readDocument(is);
-                
+
                 final NodeList styleNodes = doc.getDocumentElement().getChildNodes();
-                for (int i=0; i < styleNodes.getLength(); i++) {
+                for (int i = 0; i < styleNodes.getLength(); i++) {
                     final Node node = styleNodes.item(i);
                     if (node.getNodeType() != Node.ELEMENT_NODE) continue; // only care about elements
                     final Element tag = (Element) node;
                     String styleName = tag.getTagName();
                     XSSFBuiltinTableStyle builtIn = XSSFBuiltinTableStyle.valueOf(styleName);
-                    
+
                     Node dxfsNode = tag.getElementsByTagName("dxfs").item(0);
                     Node tableStyleNode = tag.getElementsByTagName("tableStyles").item(0);
-                    
+
                     // hack because I can't figure out how to get XMLBeans to parse a sub-element in a standalone manner
                     // - build a fake styles.xml file with just this built-in
                     StylesTable styles = new StylesTable();
@@ -413,28 +419,35 @@ public enum XSSFBuiltinTableStyle {
             throw new RuntimeException(e);
         }
     }
-    
-    private static String styleXML(Node dxfsNode, Node tableStyleNode) {
+
+    private static String styleXML(Node dxfsNode, Node tableStyleNode) throws IOException, TransformerException {
         // built-ins doc uses 1-based dxf indexing, Excel uses 0 based.
         // add a dummy node to adjust properly.
         dxfsNode.insertBefore(dxfsNode.getOwnerDocument().createElement("dxf"), dxfsNode.getFirstChild());
 
-        DOMImplementationLS lsImpl = (DOMImplementationLS)dxfsNode.getOwnerDocument().getImplementation().getFeature("LS", "3.0");
-        LSSerializer lsSerializer = lsImpl.createLSSerializer();
-        lsSerializer.getDomConfig().setParameter("xml-declaration", false);
         StringBuilder sb = new StringBuilder();
         sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n")
-        .append("<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" "
-                + "xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" "
-                + "xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" "
-                + "xmlns:x16r2=\"http://schemas.microsoft.com/office/spreadsheetml/2015/02/main\" "
-                + "mc:Ignorable=\"x14ac x16r2\">\n");
-       sb.append(lsSerializer.writeToString(dxfsNode));
-       sb.append(lsSerializer.writeToString(tableStyleNode));
-       sb.append("</styleSheet>");
-        return sb.toString(); 
+                .append("<styleSheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" ")
+                .append("xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" ")
+                .append("xmlns:x14ac=\"http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac\" ")
+                .append("xmlns:x16r2=\"http://schemas.microsoft.com/office/spreadsheetml/2015/02/main\" ")
+                .append("mc:Ignorable=\"x14ac x16r2\">\n");
+        sb.append(writeToString(dxfsNode));
+        sb.append(writeToString(tableStyleNode));
+        sb.append("</styleSheet>");
+        return sb.toString();
+    }
+
+    private static String writeToString(Node node) throws IOException, TransformerException {
+        TransformerFactory tf = TransformerFactory.newInstance();
+        try (StringWriter sw = new StringWriter()){
+            Transformer transformer = tf.newTransformer();
+            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+            transformer.transform(new DOMSource(node), new StreamResult(sw));
+            return sw.toString();
+        }
     }
-    
+
     /**
      * implementation for built-in styles
      */
@@ -451,7 +464,7 @@ public enum XSSFBuiltinTableStyle {
             this.builtIn = builtIn;
             this.style = style;
         }
-        
+
         public String getName() {
             return style.getName();
         }
@@ -463,10 +476,10 @@ public enum XSSFBuiltinTableStyle {
         public boolean isBuiltin() {
             return true;
         }
-        
+
         public DifferentialStyleProvider getStyle(TableStyleType type) {
             return style.getStyle(type);
         }
-        
+
     }
 }

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Sat Oct  6 19:33:27 2018
@@ -491,10 +491,13 @@ public final class XSSFCell implements C
                 return cell.getCellFormula(fpb);
             }
         }
-        if (f.getT() == STCellFormulaType.SHARED) {
+        if (f == null) {
+            return null;
+        } else if (f.getT() == STCellFormulaType.SHARED) {
             return convertSharedFormula((int)f.getSi(), fpb == null ? XSSFEvaluationWorkbook.create(getSheet().getWorkbook()) : fpb);
+        } else {
+            return f.getStringValue();
         }
-        return f.getStringValue();
     }
 
     /**

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFChart.java Sat Oct  6 19:33:27 2018
@@ -55,10 +55,6 @@ import org.openxmlformats.schemas.drawin
 import org.openxmlformats.schemas.drawingml.x2006.chart.CTTitle;
 import org.openxmlformats.schemas.drawingml.x2006.chart.CTTx;
 import org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextField;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Text;
@@ -262,19 +258,6 @@ public final class XSSFChart extends XDD
 
     /**
      * Returns the title static text, or null if none is set. Note that a title
-     * formula may be set instead.
-     *
-     * @return static title text, if set
-     * @deprecated POI 3.16, use {@link #getTitleText()} instead.
-     */
-    @Deprecated
-    @Removal(version = "4.0")
-    public XSSFRichTextString getTitle() {
-        return getTitleText();
-    }
-
-    /**
-     * Returns the title static text, or null if none is set. Note that a title
      * formula may be set instead. Empty text result is for backward
      * compatibility, and could mean the title text is empty or there is a
      * formula instead. Check for a formula first, falling back on text for
@@ -308,59 +291,6 @@ public final class XSSFChart extends XDD
     }
 
     /**
-     * Sets the title text as a static string.
-     *
-     * @param newTitle
-     *            to use
-     */
-    public void setTitleText(String newTitle) {
-        CTTitle ctTitle;
-        if (chart.isSetTitle()) {
-            ctTitle = chart.getTitle();
-        } else {
-            ctTitle = chart.addNewTitle();
-        }
-
-        CTTx tx;
-        if (ctTitle.isSetTx()) {
-            tx = ctTitle.getTx();
-        } else {
-            tx = ctTitle.addNewTx();
-        }
-
-        if (tx.isSetStrRef()) {
-            tx.unsetStrRef();
-        }
-
-        CTTextBody rich;
-        if (tx.isSetRich()) {
-            rich = tx.getRich();
-        } else {
-            rich = tx.addNewRich();
-            rich.addNewBodyPr(); // body properties must exist (but can be
-                                 // empty)
-        }
-
-        CTTextParagraph para;
-        if (rich.sizeOfPArray() > 0) {
-            para = rich.getPArray(0);
-        } else {
-            para = rich.addNewP();
-        }
-
-        if (para.sizeOfRArray() > 0) {
-            CTRegularTextRun run = para.getRArray(0);
-            run.setT(newTitle);
-        } else if (para.sizeOfFldArray() > 0) {
-            CTTextField fld = para.getFldArray(0);
-            fld.setT(newTitle);
-        } else {
-            CTRegularTextRun run = para.addNewR();
-            run.setT(newTitle);
-        }
-    }
-
-    /**
      * Get the chart title formula expression if there is one
      *
      * @return formula expression or null

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java Sat Oct  6 19:33:27 2018
@@ -18,7 +18,6 @@
 package org.apache.poi.xssf.usermodel;
 
 import org.apache.poi.ss.usermodel.ClientAnchor;
-import org.apache.poi.ss.usermodel.ClientAnchor.AnchorType;
 import org.apache.poi.util.Internal;
 import org.apache.poi.util.Units;
 import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
@@ -154,12 +153,6 @@ public class XSSFClientAnchor extends XS
 //        this.cell2 = calcCell(sheet, cell1, size.getCx(), size.getCy());
     }
     
-    /**
-     *
-     * @param sheet
-     * @param cell starting point and offsets (may be zeros)
-     * @param size dimensions to calculate relative to starting point
-     */
     private CTMarker calcCell(CTMarker cell, long w, long h) {
         CTMarker c2 = CTMarker.Factory.newInstance();
         

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java Sat Oct  6 19:33:27 2018
@@ -54,7 +54,7 @@ public class XSSFComment implements Comm
 
         // we potentially need to adjust the column/row information in the shape
         // the same way as we do in setRow()/setColumn()
-        if(vmlShape != null && vmlShape.sizeOfClientDataArray() > 0) {
+        if(comment != null && vmlShape != null && vmlShape.sizeOfClientDataArray() > 0) {
             CellReference ref = new CellReference(comment.getRef());
             CTClientData clientData = vmlShape.getClientDataArray(0);
             clientData.setRowArray(0, new BigInteger(String.valueOf(ref.getRow())));
@@ -70,7 +70,7 @@ public class XSSFComment implements Comm
      */
     @Override
     public String getAuthor() {
-        return _comments.getAuthor((int) _comment.getAuthorId());
+        return _comments.getAuthor(_comment.getAuthorId());
     }
 
     /**
@@ -80,9 +80,7 @@ public class XSSFComment implements Comm
      */
     @Override
     public void setAuthor(String author) {
-        _comment.setAuthorId(
-                _comments.findAuthor(author)
-        );
+        _comment.setAuthorId(_comments.findAuthor(author));
     }
 
     /**

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Sat Oct  6 19:33:27 2018
@@ -2262,8 +2262,8 @@ public class XSSFSheet extends POIXMLDoc
         }
     }
 
-    private void unsetCollapsed(boolean collapsed, CTCol ci) {
-        if (collapsed) {
+    private void unsetCollapsed(Boolean collapsed, CTCol ci) {
+        if (collapsed != null && collapsed.booleanValue()) {
             ci.setCollapsed(collapsed);
         } else {
             ci.unsetCollapsed();
@@ -2410,7 +2410,7 @@ public class XSSFSheet extends POIXMLDoc
         boolean endHidden = false;
         int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup(idx);
         CTCol[] colArray = cols.getColArray();
-        if (endOfOutlineGroupIdx < colArray.length) {
+        if (endOfOutlineGroupIdx < (colArray.length - 1)) {
             CTCol nextInfo = colArray[endOfOutlineGroupIdx + 1];
             if (isAdjacentBefore(colArray[endOfOutlineGroupIdx], nextInfo)) {
                 endLevel = nextInfo.getOutlineLevel();
@@ -2900,7 +2900,7 @@ public class XSSFSheet extends POIXMLDoc
                 //            "Got srcRows[" + (index-1) + "]=Row " + prevRow.getRowNum() + ", srcRows[" + index + "]=Row " + curRow.getRowNum() + ".");
                 // FIXME: assumes row objects belong to non-null sheets and sheets belong to non-null workbooks.
             } else if (srcStartRow.getSheet().getWorkbook() != curRow.getSheet().getWorkbook()) {
-                throw new IllegalArgumentException("All rows in srcRows must belong to the same sheet in the same workbook." +
+                throw new IllegalArgumentException("All rows in srcRows must belong to the same sheet in the same workbook. " +
                         "Expected all rows from same workbook (" + srcStartRow.getSheet().getWorkbook() + "). " +
                         "Got srcRows[" + index + "] from different workbook (" + curRow.getSheet().getWorkbook() + ").");
             } else if (srcStartRow.getSheet() != curRow.getSheet()) {

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java Sat Oct  6 19:33:27 2018
@@ -283,7 +283,7 @@ public class XSSFTable extends POIXMLDoc
         }
         
         // check if name is unique and calculate unique column id 
-        long nextColumnId = 1; 
+        long nextColumnId = 0; 
         for (XSSFTableColumn tableColumn : getColumns()) {
             if (columnName != null && columnName.equalsIgnoreCase(tableColumn.getName())) {
                 throw new IllegalArgumentException("Column '" + columnName
@@ -291,6 +291,8 @@ public class XSSFTable extends POIXMLDoc
             }
             nextColumnId = Math.max(nextColumnId, tableColumn.getId());
         }
+        // Bug #62740, the logic was just re-using the existing max ID, not incrementing beyond it.
+        nextColumnId++;
         
         // Add the new Column
         CTTableColumn column = columns.insertNewTableColumn(columnIndex);
@@ -474,14 +476,9 @@ public class XSSFTable extends POIXMLDoc
      * this method does not create or remove any columns and does not change any
      * cell values.
      * 
-     * @deprecated Use {@link #setTableArea} instead, which will ensure that the
-     *             the amount of columns always matches table area always width.
-     * 
      * @see "Open Office XML Part 4: chapter 3.5.1.2, attribute ref"
      * @since 3.17 beta 1
      */
-    @Deprecated
-    @Removal(version="4.2.0")
     public void setCellReferences(AreaReference refs) {
         setCellRef(refs);
     }
@@ -525,7 +522,7 @@ public class XSSFTable extends POIXMLDoc
      * Updating the area with this method will create new column as necessary to
      * the right side of the table but will not modify any cell values.
      * 
-     * @param refs
+     * @param tableArea
      *            the new area of the table
      * @throws IllegalArgumentException
      *             if the area is {@code null} or not

Modified: poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java (original)
+++ poi/branches/hemf/src/ooxml/java/org/apache/poi/xssf/usermodel/helpers/XSSFFormulaUtils.java Sat Oct  6 19:33:27 2018
@@ -19,6 +19,10 @@
 
 package org.apache.poi.xssf.usermodel.helpers;
 
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.poi.ooxml.POIXMLDocumentPart;
 import org.apache.poi.ss.formula.FormulaParser;
 import org.apache.poi.ss.formula.FormulaRenderer;
 import org.apache.poi.ss.formula.FormulaType;
@@ -30,10 +34,14 @@ import org.apache.poi.ss.usermodel.CellT
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFChart;
+import org.apache.poi.xssf.usermodel.XSSFDrawing;
 import org.apache.poi.xssf.usermodel.XSSFEvaluationWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFName;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 /**
  * Utility to update formulas and named ranges when a sheet name was changed
@@ -50,7 +58,7 @@ public final class XSSFFormulaUtils {
     }
 
     /**
-     * Update sheet name in all formulas and named ranges.
+     * Update sheet name in all charts, formulas and named ranges.
      * Called from {@link XSSFWorkbook#setSheetName(int, String)}
      * <p>
      * <p>
@@ -81,6 +89,20 @@ public final class XSSFFormulaUtils {
                 }
             }
         }
+
+        // update charts
+        List<POIXMLDocumentPart> rels = _wb.getSheetAt(sheetIndex).getRelations();
+        for (POIXMLDocumentPart r : rels) {
+            if (r instanceof XSSFDrawing) {
+                XSSFDrawing dg = (XSSFDrawing) r;
+                Iterator<XSSFChart> it = dg.getCharts().iterator();
+                while (it.hasNext()) {
+                    XSSFChart chart = it.next();
+                    Node dom = chart.getCTChartSpace().getDomNode();
+                    updateDomSheetReference(dom, oldName, newName);
+                }
+            }
+        }
     }
 
     /**
@@ -99,7 +121,9 @@ public final class XSSFFormulaUtils {
                     updatePtg(ptg, oldName, newName);
                 }
                 String updatedFormula = FormulaRenderer.toFormulaString(_fpwb, ptgs);
-                if (!formula.equals(updatedFormula)) f.setStringValue(updatedFormula);
+                if (!formula.equals(updatedFormula)) {
+                    f.setStringValue(updatedFormula);
+                }
             }
         }
     }
@@ -119,10 +143,12 @@ public final class XSSFFormulaUtils {
                 updatePtg(ptg, oldName, newName);
             }
             String updatedFormula = FormulaRenderer.toFormulaString(_fpwb, ptgs);
-            if (!formula.equals(updatedFormula)) name.setRefersToFormula(updatedFormula);
+            if (!formula.equals(updatedFormula)) {
+                name.setRefersToFormula(updatedFormula);
+            }
         }
     }
-    
+
     private void updatePtg(Ptg ptg, String oldName, String newName) {
         if (ptg instanceof Pxg) {
             Pxg pxg = (Pxg)ptg;
@@ -141,4 +167,32 @@ public final class XSSFFormulaUtils {
             }
         }
     }
+
+
+    /**
+     * Parse the DOM tree recursively searching for text containing reference to the old sheet name and replacing it.
+     *
+     * @param dom the XML node in which to perform the replacement.
+     *
+     * Code extracted from: <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=54470">Bug 54470</a>
+     */
+    private void updateDomSheetReference(Node dom, final String oldName, final String newName) {
+        String value = dom.getNodeValue();
+        if (value != null) {
+            // make sure the value contains the old sheet and not a similar sheet
+            // (ex: Valid: 'Sheet1'! or Sheet1! ; NotValid: 'Sheet1Test'! or Sheet1Test!)
+            if (value.contains(oldName+"!") || value.contains(oldName+"'!")) {
+                XSSFName temporary = _wb.createName();
+                temporary.setRefersToFormula(value);
+                updateName(temporary, oldName, newName);
+                dom.setNodeValue(temporary.getRefersToFormula());
+                _wb.removeName(temporary);
+            }
+        }
+        NodeList nl = dom.getChildNodes();
+        for (int i = 0; i < nl.getLength(); i++) {
+            updateDomSheetReference(nl.item(i), oldName, newName);
+        }
+    }
+
 }

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/util/OOXMLLite.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/util/OOXMLLite.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/util/OOXMLLite.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/util/OOXMLLite.java Sat Oct  6 19:33:27 2018
@@ -17,6 +17,18 @@
 
 package org.apache.poi.ooxml.util;
 
+import junit.framework.TestCase;
+import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.StringUtil;
+import org.apache.poi.util.SuppressForbidden;
+import org.apache.xmlbeans.StringEnumAbstractBase;
+import org.junit.Test;
+import org.junit.internal.TextListener;
+import org.junit.runner.Description;
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Result;
+import org.reflections.Reflections;
+
 import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.Field;
@@ -26,29 +38,11 @@ import java.security.AccessController;
 import java.security.CodeSource;
 import java.security.PrivilegedAction;
 import java.security.ProtectionDomain;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Vector;
+import java.util.*;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.regex.Pattern;
 
-import junit.framework.TestCase;
-
-import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.StringUtil;
-import org.apache.poi.util.SuppressForbidden;
-import org.junit.Test;
-import org.junit.internal.TextListener;
-import org.junit.runner.Description;
-import org.junit.runner.JUnitCore;
-import org.junit.runner.Result;
-
 /**
  * Build a 'lite' version of the ooxml-schemas.jar
  *
@@ -193,20 +187,37 @@ public final class OOXMLLite {
 
         //see what classes from the ooxml-schemas.jar are loaded
         System.out.println("Copying classes to " + _destDest);
-        Map<String, Class<?>> classes = getLoadedClasses(_ooxmlJar.getName());
-        for (Class<?> cls : classes.values()) {
-            String className = cls.getName();
-            String classRef = className.replace('.', '/') + ".class";
-            File destFile = new File(_destDest, classRef);
-            IOUtils.copy(cls.getResourceAsStream('/' + classRef), destFile);
+        Set<Class<?>> classes = getLoadedClasses(_ooxmlJar.getName());
+        Set<String> packages = new HashSet<>();
+        for (Class<?> cls : classes) {
+            copyFile(cls);
+            packages.add(cls.getPackage().getName());
 
-            if(cls.isInterface()){
+            if (cls.isInterface()) {
                 /// Copy classes and interfaces declared as members of this class
-                for(Class<?> fc : cls.getDeclaredClasses()){
-                    className = fc.getName();
-                    classRef = className.replace('.', '/') + ".class";
-                    destFile = new File(_destDest, classRef);
-                    IOUtils.copy(fc.getResourceAsStream('/' + classRef), destFile);
+                for (Class<?> fc : cls.getDeclaredClasses()) {
+                    copyFile(fc);
+                }
+            }
+        }
+        for (String pkg : packages) {
+            Reflections reflections = new Reflections(pkg);
+            Set<Class<? extends List>> listClasses = reflections.getSubTypesOf(List.class);
+            listClasses.removeAll(classes);
+            for (Class listClass : listClasses) {
+                for (Class<?> compare : classes) {
+                    if (listClass.getName().startsWith(compare.getName())) {
+                        copyFile(listClass);
+                    }
+                }
+            }
+            Set<Class<? extends StringEnumAbstractBase>> enumClasses = reflections.getSubTypesOf(StringEnumAbstractBase.class);
+            listClasses.removeAll(classes);
+            for (Class enumClass : enumClasses) {
+                for (Class<?> compare : classes) {
+                    if (enumClass.getName().startsWith(compare.getName())) {
+                        copyFile(enumClass);
+                    }
                 }
             }
         }
@@ -224,6 +235,13 @@ public final class OOXMLLite {
         }
     }
 
+    private void copyFile(Class<?> cls) throws IOException {
+        String className = cls.getName();
+        String classRef = className.replace('.', '/') + ".class";
+        File destFile = new File(_destDest, classRef);
+        IOUtils.copy(cls.getResourceAsStream('/' + classRef), destFile);
+    }
+
     private static boolean checkForTestAnnotation(Class<?> testclass) {
         for (Method m : testclass.getDeclaredMethods()) {
             if(m.isAnnotationPresent(Test.class)) {
@@ -293,10 +311,10 @@ public final class OOXMLLite {
     /**
      *
      * @param ptrn the pattern to filter output
-     * @return the classes loaded by the system class loader keyed by class name
+     * @return the classes loaded by the system class loader
      */
     @SuppressWarnings("unchecked")
-    private static Map<String, Class<?>> getLoadedClasses(String ptrn) {
+    private static Set<Class<?>> getLoadedClasses(String ptrn) {
         // make the field accessible, we defer this from static initialization to here to 
         // allow JDKs which do not have this field (e.g. IBM JDK) to at least load the class
         // without failing, see https://issues.apache.org/bugzilla/show_bug.cgi?id=56550
@@ -317,7 +335,7 @@ public final class OOXMLLite {
         ClassLoader appLoader = ClassLoader.getSystemClassLoader();
         try {
             Vector<Class<?>> classes = (Vector<Class<?>>) _classes.get(appLoader);
-            Map<String, Class<?>> map = new HashMap<>();
+            Set<Class<?>> set = new HashSet<>();
             for (Class<?> cls : classes) {
                 // e.g. proxy-classes, ...
                 ProtectionDomain pd = cls.getProtectionDomain();
@@ -326,13 +344,13 @@ public final class OOXMLLite {
                 if (cs == null) continue;
                 URL loc = cs.getLocation();
                 if (loc == null) continue;
-                
+
                 String jar = loc.toString();
                 if (jar.contains(ptrn)) {
-                    map.put(cls.getName(), cls);
+                    set.add(cls);
                 }
             }
-            return map;
+            return set;
         } catch (IllegalAccessException e) {
             throw new RuntimeException(e);
         }

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java Sat Oct  6 19:33:27 2018
@@ -37,8 +37,12 @@ public class TestDocumentHelper {
 
     @Test
     public void testDocumentBuilderFactory() throws Exception {
-        assertTrue(DocumentHelper.documentBuilderFactory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
-        assertFalse(DocumentHelper.documentBuilderFactory.getFeature(POIXMLConstants.FEATURE_LOAD_DTD_GRAMMAR));
-        assertFalse(DocumentHelper.documentBuilderFactory.getFeature(POIXMLConstants.FEATURE_LOAD_EXTERNAL_DTD));
+        try {
+            assertTrue(DocumentHelper.documentBuilderFactory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
+            assertFalse(DocumentHelper.documentBuilderFactory.getFeature(POIXMLConstants.FEATURE_LOAD_DTD_GRAMMAR));
+            assertFalse(DocumentHelper.documentBuilderFactory.getFeature(POIXMLConstants.FEATURE_LOAD_EXTERNAL_DTD));
+        } catch(AbstractMethodError e) {
+            // ignore exceptions from old parsers that don't support this API (https://bz.apache.org/bugzilla/show_bug.cgi?id=62692)
+        }
     }
 }

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/util/TestSAXHelper.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/util/TestSAXHelper.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/util/TestSAXHelper.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/ooxml/util/TestSAXHelper.java Sat Oct  6 19:33:27 2018
@@ -24,6 +24,7 @@ import javax.xml.XMLConstants;
 
 import org.junit.Test;
 import org.xml.sax.InputSource;
+import org.xml.sax.SAXNotRecognizedException;
 import org.xml.sax.XMLReader;
 
 public class TestSAXHelper {
@@ -31,14 +32,18 @@ public class TestSAXHelper {
     public void testXMLReader() throws Exception {
         XMLReader reader = SAXHelper.newXMLReader();
         assertNotSame(reader, SAXHelper.newXMLReader());
-        assertTrue(reader.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
-        assertFalse(reader.getFeature(POIXMLConstants.FEATURE_LOAD_DTD_GRAMMAR));
-        assertFalse(reader.getFeature(POIXMLConstants.FEATURE_LOAD_EXTERNAL_DTD));
-        assertEquals(SAXHelper.IGNORING_ENTITY_RESOLVER, reader.getEntityResolver());
-        assertNotNull(reader.getProperty(POIXMLConstants.PROPERTY_ENTITY_EXPANSION_LIMIT));
-        assertEquals("1", reader.getProperty(POIXMLConstants.PROPERTY_ENTITY_EXPANSION_LIMIT));
-        assertNotNull(reader.getProperty(POIXMLConstants.PROPERTY_SECURITY_MANAGER));
-
+        try {
+            assertTrue(reader.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING));
+            assertFalse(reader.getFeature(POIXMLConstants.FEATURE_LOAD_DTD_GRAMMAR));
+            assertFalse(reader.getFeature(POIXMLConstants.FEATURE_LOAD_EXTERNAL_DTD));
+            assertEquals(SAXHelper.IGNORING_ENTITY_RESOLVER, reader.getEntityResolver());
+            assertNotNull(reader.getProperty(POIXMLConstants.PROPERTY_ENTITY_EXPANSION_LIMIT));
+            assertEquals("1", reader.getProperty(POIXMLConstants.PROPERTY_ENTITY_EXPANSION_LIMIT));
+            assertNotNull(reader.getProperty(POIXMLConstants.PROPERTY_SECURITY_MANAGER));
+        } catch(SAXNotRecognizedException e) {
+            // ignore exceptions from old parsers that don't support these features
+            // (https://bz.apache.org/bugzilla/show_bug.cgi?id=62692)
+        }
         reader.parse(new InputSource(new ByteArrayInputStream("<xml></xml>".getBytes("UTF-8"))));
     }
 }

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java Sat Oct  6 19:33:27 2018
@@ -907,7 +907,7 @@ public final class TestPackage {
 		getZipStatsAndConsume((max_size, min_ratio) -> {
 			// check max entry size ouf of bounds
 			ZipSecureFile.setMinInflateRatio(min_ratio-0.002);
-			ZipSecureFile.setMaxEntrySize(max_size-100);
+			ZipSecureFile.setMaxEntrySize(max_size-200);
 		});
 	}
 
@@ -925,8 +925,8 @@ public final class TestPackage {
 				if (ze.getSize() == 0) {
 					continue;
 				}
-				// add zip entry header ~ 30 bytes
-				long size = ze.getSize()+30;
+				// add zip entry header ~ 128 bytes
+				long size = ze.getSize()+128;
 				double ratio = ze.getCompressedSize() / (double)size;
 				min_ratio = Math.min(min_ratio, ratio);
 				max_size = Math.max(max_size, size);

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java Sat Oct  6 19:33:27 2018
@@ -93,6 +93,87 @@ import org.openxmlformats.schemas.presen
 public class TestXSLFBugs {
     private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
 
+    @Test
+    public void bug62736() throws Exception {
+        XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("bug62736.pptx");
+
+        assertEquals(1, ss1.getSlides().size());
+
+        XSLFSlide slide0 = ss1.getSlides().get(0);
+
+        assertEquals(slide0.getShapes().size(), 4);
+
+        assertRelation(slide0, "/ppt/slides/slide1.xml", null);
+        assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
+        assertRelation(slide0, "/ppt/media/image1.png", "rId2");
+        assertEquals(slide0.getRelations().size(), 2);
+
+        List<XSLFPictureShape> pictures = new ArrayList<>();
+        for (XSLFShape shape : slide0.getShapes()) {
+            if (shape instanceof XSLFPictureShape) {
+                pictures.add((XSLFPictureShape) shape);
+            }
+        }
+
+        assertEquals(pictures.size(), 2);
+        assertEquals(pictures.get(0).getPictureData().getFileName(), "image1.png");
+        assertEquals(pictures.get(1).getPictureData().getFileName(), "image1.png");
+        // blipId is rId2 of both pictures
+
+        // remove just the first picture
+        slide0.removeShape(pictures.get(0));
+
+        assertEquals(slide0.getShapes().size(), 3);
+
+        assertRelation(slide0, "/ppt/slides/slide1.xml", null);
+        assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
+        // the bug is that the following relation is gone
+        assertRelation(slide0, "/ppt/media/image1.png", "rId2");
+        assertEquals(slide0.getRelations().size(), 2);
+
+        // Save and re-load
+        XMLSlideShow ss2 = XSLFTestDataSamples.writeOutAndReadBack(ss1);
+        ss1.close();
+        assertEquals(1, ss2.getSlides().size());
+
+        slide0 = ss2.getSlides().get(0);
+
+        assertRelation(slide0, "/ppt/slides/slide1.xml", null);
+        assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
+        assertRelation(slide0, "/ppt/media/image1.png", "rId2");
+        assertEquals(slide0.getRelations().size(), 2);
+
+        pictures.clear();
+        for (XSLFShape shape : slide0.getShapes()) {
+            if (shape instanceof XSLFPictureShape) {
+                pictures.add((XSLFPictureShape) shape);
+            }
+        }
+
+        assertEquals(pictures.size(), 1);
+        assertEquals(pictures.get(0).getPictureData().getFileName(), "image1.png");
+
+        slide0.removeShape(pictures.get(0));
+
+        assertEquals(slide0.getShapes().size(), 2);
+
+        assertRelation(slide0, "/ppt/slides/slide1.xml", null);
+        assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
+        assertNull(slide0.getRelationById("rId2"));
+        assertEquals(slide0.getRelations().size(), 1);
+
+        // Save and re-load
+        XMLSlideShow ss3 = XSLFTestDataSamples.writeOutAndReadBack(ss2);
+        ss2.close();
+        assertEquals(1, ss3.getSlides().size());
+
+        slide0 = ss3.getSlides().get(0);
+
+        assertRelation(slide0, "/ppt/slides/slide1.xml", null);
+        assertRelation(slide0, "/ppt/slideLayouts/slideLayout1.xml", "rId1");
+        assertEquals(slide0.getShapes().size(), 2);
+        ss3.close();
+    }
 
     @Test
     public void bug61589() throws IOException {

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFChart.java Sat Oct  6 19:33:27 2018
@@ -158,7 +158,7 @@ public class TestXSLFChart {
         final XDDFNumericalDataSource<Integer> valuesData = XDDFDataSourcesFactory.fromArray(values, valuesDataRange);
         series.replaceData(categoryData, valuesData);
         final String title = "Apache POI";
-        series.setTitle(title, chart.setSheetTitle(title));
+        series.setTitle(title, chart.setSheetTitle(title, 0));
         chart.plot(data);
 	}
 

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java Sat Oct  6 19:33:27 2018
@@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -395,15 +396,21 @@ public final class TestXSSFTable {
         assertEquals(2, table.getRowCount());
 
         // add columns
-        table.createColumn("Column B");
-        table.createColumn("Column D");
-        table.createColumn("Column C", 2); // add between B and D
+        XSSFTableColumn c1 = table.getColumns().get(0);
+        XSSFTableColumn cB = table.createColumn("Column B");
+        XSSFTableColumn cD = table.createColumn("Column D");
+        XSSFTableColumn cC = table.createColumn("Column C", 2); // add between B and D
         table.updateReferences();
         table.updateHeaders();
 
         assertEquals(4, table.getColumnCount());
         assertEquals(2, table.getRowCount());
 
+        // column IDs start at 1, and increase in the order columns are added (see bug #62740)
+        assertEquals("Column c ID", 1, c1.getId());
+        assertTrue("Column B ID", c1.getId() < cB.getId());
+        assertTrue("Column D ID", cB.getId() < cD.getId());
+        assertTrue("Column C ID", cD.getId() < cC.getId());
         assertEquals("Column 1", table.getColumns().get(0).getName()); // generated name
         assertEquals("Column B", table.getColumns().get(1).getName());
         assertEquals("Column C", table.getColumns().get(2).getName());

Modified: poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (original)
+++ poi/branches/hemf/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java Sat Oct  6 19:33:27 2018
@@ -39,8 +39,8 @@ import java.util.List;
 import java.util.zip.CRC32;
 
 import org.apache.poi.POIDataSamples;
-import org.apache.poi.ooxml.POIXMLProperties;
 import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.ooxml.POIXMLProperties;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.opc.ContentTypes;
 import org.apache.poi.openxml4j.opc.OPCPackage;
@@ -67,6 +67,8 @@ import org.apache.poi.ss.util.CellRefere
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LocaleUtil;
 import org.apache.poi.util.TempFile;
+import org.apache.poi.xddf.usermodel.chart.XDDFBarChartData;
+import org.apache.poi.xddf.usermodel.chart.XDDFChartData;
 import org.apache.poi.xssf.XSSFITestDataProvider;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.model.StylesTable;
@@ -553,7 +555,9 @@ public final class TestXSSFWorkbook exte
         Sheet sheet = wb.getSheetAt(0);
         sheet.shiftRows(2, sheet.getLastRowNum(), 1, true, false);
         Row newRow = sheet.getRow(2);
-        if (newRow == null) newRow = sheet.createRow(2);
+        if (newRow == null) {
+            newRow = sheet.createRow(2);
+        }
         newRow.createCell(0).setCellValue(" Another Header");
         wb.cloneSheet(0);
 
@@ -667,8 +671,8 @@ public final class TestXSSFWorkbook exte
         XSSFWorkbook wb3 = XSSFTestDataSamples.writeOutAndReadBack(wb2);
         assertNotNull(wb3);
         sheet = wb3.getSheetAt(0);
-        row = sheet.getRow(2);        
-        
+        row = sheet.getRow(2);
+
         assertEquals("test1", row.getCell(3).getStringCellValue());
         assertEquals("test2", row.getCell(4).getStringCellValue());
         wb3.close();
@@ -700,6 +704,24 @@ public final class TestXSSFWorkbook exte
         }
     }
 
+    @Test
+    public void bug60509() throws Exception {
+        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("60509.xlsx");
+        assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3");
+        int sheetIndex = wb.getSheetIndex("Sheet1");
+        wb.setSheetName(sheetIndex, "Sheet1-Renamed");
+        Workbook read = XSSFTestDataSamples.writeOutAndReadBack(wb);
+        assertNotNull(read);
+        assertSheetOrder(read, "Sheet1-Renamed", "Sheet2", "Sheet3");
+        XSSFSheet sheet = (XSSFSheet) read.getSheet("Sheet1-Renamed");
+        XDDFChartData.Series series = sheet.getDrawingPatriarch().getCharts().get(0).getChartSeries().get(0).getSeries().get(0);
+        assertTrue("should be a bar chart data series", series instanceof XDDFBarChartData.Series);
+        String formula = ((XDDFBarChartData.Series) series).getCategoryData().getFormula();
+        assertTrue("should contain new sheet name", formula.startsWith("'Sheet1-Renamed'!"));
+        read.close();
+        wb.close();
+    }
+
     private static final int INDEX_NOT_FOUND = -1;
 
     private static boolean isEmpty(CharSequence cs) {
@@ -1009,22 +1031,22 @@ public final class TestXSSFWorkbook exte
         final String filename = "SampleSS.xlsx";
         final File file = POIDataSamples.getSpreadSheetInstance().getFile(filename);
         Workbook wb;
-        
+
         // Some tests commented out because close() modifies the file
         // See bug 58779
-        
+
         // String
         //wb = new XSSFWorkbook(file.getPath());
         //assertCloseDoesNotModifyFile(filename, wb);
-        
+
         // File
         //wb = new XSSFWorkbook(file);
         //assertCloseDoesNotModifyFile(filename, wb);
-        
+
         // InputStream
         wb = new XSSFWorkbook(new FileInputStream(file));
         assertCloseDoesNotModifyFile(filename, wb);
-        
+
         // OPCPackage
         //wb = new XSSFWorkbook(OPCPackage.open(file));
         //assertCloseDoesNotModifyFile(filename, wb);
@@ -1070,7 +1092,7 @@ public final class TestXSSFWorkbook exte
        XSSFTable table2 = wb.getSheet("Foglio2").createTable();
        table2.setName("Table2");
        assertSame("Did not find Table2", table2, wb.getTable("Table2"));
-       
+
        // If table name is modified after getTable is called, the table can only be found by its new name
        // This test makes sure that if any caching is done that getTable never uses a stale cache
        table1.setName("Table1");

Modified: poi/branches/hemf/src/resources/devtools/forbidden-signatures.txt
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/resources/devtools/forbidden-signatures.txt?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/resources/devtools/forbidden-signatures.txt (original)
+++ poi/branches/hemf/src/resources/devtools/forbidden-signatures.txt Sat Oct  6 19:33:27 2018
@@ -123,6 +123,11 @@ java.util.concurrent.Future#cancel(boole
 @defaultMessage Don't use ...InputStream.available() as it gives wrong result for certain streams - use IOUtils.toByteArray to read the stream fully and then count the available bytes 
 java.io.InputStream#available() 
 
+@defaultMessage Use newInstance, as newFactory does not seem to work on Android - https://github.com/centic9/poi-on-android/issues/44#issuecomment-426517981
+javax.xml.stream.XMLEventFactory#newFactory()
+javax.xml.stream.XMLInputFactory#newFactory()
+javax.xml.stream.XMLOutputFactory#newFactory()
+
 @defaultMessage Unnecessary, inefficient, and confusing conversion of String.toString
 java.lang.String#toString()
 

Modified: poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoRun.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoRun.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoRun.java (original)
+++ poi/branches/hemf/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoRun.java Sat Oct  6 19:33:27 2018
@@ -187,7 +187,7 @@ public class TextSpecInfoRun {
             smartTagFld, smartTagsBytes, "smart tags"
         };
         
-        for (int i=0; i<flds.length; i+=3) {
+        for (int i=0; i<flds.length-1; i+=3) {
             BitField fld = (BitField)flds[i+0];
             Object valO = flds[i+1];
             if (!fld.isSet(mask)) continue;
@@ -210,7 +210,8 @@ public class TextSpecInfoRun {
                 valid = false;
             }
             if (!valid) {
-                throw new IOException(flds[i+2]+" is activated, but its value is invalid");
+                Object fval = (i + 2) < flds.length ? flds[i + 2] : null;
+                throw new IOException(fval + " is activated, but its value is invalid");
             }
         }
     }        

Modified: poi/branches/hemf/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java
URL: http://svn.apache.org/viewvc/poi/branches/hemf/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java?rev=1843032&r1=1843031&r2=1843032&view=diff
==============================================================================
--- poi/branches/hemf/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java (original)
+++ poi/branches/hemf/src/testcases/org/apache/poi/ss/formula/atp/TestRandBetween.java Sat Oct  6 19:33:27 2018
@@ -53,12 +53,6 @@ public class TestRandBetween extends Tes
 		formulaCell = row.createCell(2, CellType.FORMULA);
 	}
 	
-	@Override
-	protected void tearDown() throws Exception {
-		// TODO Auto-generated method stub
-		super.tearDown();
-	}
-	
 	/**
 	 * Check where values are the same
 	 */
@@ -74,6 +68,17 @@ public class TestRandBetween extends Tes
 		assertEquals(-1, formulaCell.getNumericCellValue(), 0);
 
 	}
+
+	public void testRandBetweenLargeLongs() {
+        for (int i = 0; i < 100; i++) {
+            evaluator.clearAllCachedResultValues();
+            formulaCell.setCellFormula("RANDBETWEEN(0,9999999999)");
+            evaluator.evaluateFormulaCell(formulaCell);
+            double value = formulaCell.getNumericCellValue();
+            assertTrue("rand is greater than or equal to lowerbound", value >= 0.0);
+            assertTrue("rand is less than or equal to upperbound", value <= 9999999999.0);
+        }
+	}
 	
 	/**
 	 * Check special case where rounded up bottom value is greater than 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org