DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=37101>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=37101

           Summary: Save sheets with comments cannot be reopened (in Excel
                    or HSSF)
           Product: POI
           Version: 3.0-dev
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: HSSF
        AssignedTo: [email protected]
        ReportedBy: [EMAIL PROTECTED]


If you open an .xls containing cell comments and save it using 
HSSFWorkbook.write() the resulting document will not open successfully using 
either Excel or Poi.  The problem is manifested in the serialize() method of 
class TextObjectRecord.  The serialize() method only outputs a string if there 
is one to export.  Even though one is read in (and the field length and format 
properties indicate there is a string) the serialize() method sees an empty 
string.  However the cause of the problem is not in serialize() but in the 
class constructor.

The class has a variable, 'str', that is initialised *and* is set by the 
virtual method fillFields().  The problem arises because fillFields is called 
in the constructor.  Java seems to run the constructor code (and super()) THEN 
initialise class variables.  The effect is that no matter what value the str 
variable is assigned when fillFields() is called by the constructor, the value 
it has when the constructor is complete is the value it is assigned when the 
variable is initialised in the class (ie and empty string).

The solution is to assign a default value to variable 'str' in the constructor 
before calling super() rather than initialize it.

Here are a couple of very short classes that show the same effect.  In these 
examples, MethodToOverride() is the equivalent of fillFields().  It is called 
form the parent constructor just as fillFields() is called by the Record() 
constructor (which is the ultimate parent of TextObjectRecord.

In this example, the end value of the class variable is BBB not the XXX set 
MethodToOverride().  This shows that Java initialises class variable after 
completing the constructor.

public abstract class ABaseClass
{
        public ABaseClass()
        {
                MethodToOverride();
        }
        protected abstract void MethodToOverride();
}

public class DerivedClass extends ABaseClass
{
        public String SomeDerivedString = "BBB";

        public DerivedClass() 
        {
                super();
        }

        protected void MethodToOverride()
        {
                System.out.println( "Overridden method before'" + 
SomeDerivedString + "'");
                SomeDerivedString = "XXX";
                SomeDerivedInt = 99;
                System.out.println( "Overridden method after '" + 
SomeDerivedString + "'");
        }

        public static void main(String [] args)
    {
                DerivedClass d = new DerivedClass();
                System.out.println( d.SomeDerivedString );
        }
}

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/

Reply via email to