https://bz.apache.org/bugzilla/show_bug.cgi?id=60985

Javen O'Neal <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #6 from Javen O'Neal <[email protected]> ---
Here's what I had in mind for the fix:

Index: src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
===================================================================
--- src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java       (revision
1791876)
+++ src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java       (working copy)
@@ -40,6 +40,7 @@
 import org.apache.poi.hssf.record.ExtendedFormatRecord;
 import org.apache.poi.hssf.record.HyperlinkRecord;
 import org.apache.poi.hssf.record.NameRecord;
+import org.apache.poi.hssf.record.PrintSetupRecord;
 import org.apache.poi.hssf.record.Record;
 import org.apache.poi.hssf.record.RecordBase;
 import org.apache.poi.hssf.record.RowRecord;
@@ -1242,7 +1243,8 @@
      */
     @Override
     public HSSFPrintSetup getPrintSetup() {
-        return new HSSFPrintSetup(_sheet.getPageSettings().getPrintSetup());
+        final PrintSetupRecord r = _sheet.getPageSettings().getPrintSetup();
+        return (r==null) ? null : new HSSFPrintSetup(r);
     }

     @Override

However, getMargin and setMargin will also throw NPEs if no PrintSetupRecord is
present. Should we change HSSFSheet#getPrintSetup() to add a new
PrintSetupRecord if none exists? This would mean that a getter has a
side-effect, which may be unexpected (especially for read-only behavior).
We could have getPrintSetup() return null, forcing the caller to call
HSSFSheet#add/createPrintSetup() (method doesn't exist yet), but this would
result in uglier and likely-to-be-incorrect user code.

Currently Ivan gets an NPE because HSSFSheet#getPrintSetup() returns new
HSSFPrintSetup(PrintSetupRecord rec=null), and calling setLandscape(Boolean) on
a non-null HSSFPrintSetup that wraps a null PrintSetupRecord doesn't have a
logical behavior.

Any opinions on what the best solution is here?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to