[
https://issues.apache.org/jira/browse/ODFTOOLKIT-133?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13132540#comment-13132540
]
Devin Han commented on ODFTOOLKIT-133:
--------------------------------------
I ran the test case with ODFDOM 0.8.7 and found that there is no exception even
using IBM JDK.
It's interesting. After dive into the code, I found that the new generated
element/attribute classes have removed methods getValue()/setValue() and there
are bugs in both of them. Take TextStyleNameAttribute as example:
public void setValue(String attrValue) {
OdfElement parentElement = (OdfElement)getOwnerElement();
if( parentElement != null ){
try {
if( parentElement instanceof TextAElement ){
//2DO: need validate value against
StyleNameRef
super.setValue(attrValue);
}else if( parentElement instanceof
TextAlphabeticalIndexElement ){
//2DO: need validate value against
StyleNameRef
...
}else if( parentElement instanceof
TextUserIndexEntryTemplateElement ){
//2DO: need validate value against
StyleNameRef
super.setValue(attrValue);
}
------------------------------------------------------------------------------------------------>no
else, that will lead to give a null to this attribute
} catch (NullPointerException e) {
// TODO: validation handling/logging
throw new IllegalArgumentException(e);
}
catch (IllegalArgumentException e) {
// TODO: validation handling/logging
throw (e);
}
}else{
//2DO:what should do when the owner element is null?
super.setValue(attrValue);
}
}
public String getValue(){
OdfElement parentElement = (OdfElement)getOwnerElement();
if( parentElement != null ){
try {
if( parentElement instanceof TextAElement ){
//2DO: need validate value against
StyleNameRef
return super.getValue();
}else if( parentElement instanceof
TextAlphabeticalIndexElement ){
.....
}else if( parentElement instanceof
TextUserIndexEntryTemplateElement ){
//2DO: need validate value against
StyleNameRef
return super.getValue();
}
---------------------------------------------------------------------------------------------------------------->no
else, that will lead to return null to this attribute
} catch (IllegalArgumentException e) {
// TODO: validation handling/logging
throw new NumberFormatException("the value of
text:style-name is not valid");
}
}else{
//2DO:what should do when the owner element is null?
return super.getValue();
}
return null;
}
and in OdfElement the startElement method will call getValue/setValue to
initialize the Attribute value. Null maybe set. IBM JDK have more serious
check, so exception will be thrown. But it's not a fault of IBM JDK, it is
caused by our code.
Fortunately, we have fixed it in 0.8.7, according call the methods in class
AttributesImpl directly. So I will mark this issue as fixed.
> NullPointerException sometimes happened when parsing a centain kind of XML
> under IBM JDK
> ----------------------------------------------------------------------------------------
>
> Key: ODFTOOLKIT-133
> URL: https://issues.apache.org/jira/browse/ODFTOOLKIT-133
> Project: ODF Toolkit
> Issue Type: Bug
> Components: java
> Affects Versions: 0.8.5
> Environment: Operating System: All
> Platform: All
> Reporter: kelvin
> Assignee: Ying Chun Guo
> Fix For: 0.8.7
>
> Attachments: EditMetadata.java, bug202_failuretest.patch, test.odp
>
>
> Created an attachment (id=303)
> testcase code
> I needed to change the creator name in some presentations that I am working
> on as I borrowed a slide deck from someone to get her look and feel. However
> I did not want her name showing up as the presentation creator. As Open
> Office and Symphony offer no way to edit this field I wrote the attached
> small program to do it.
> In my testing I found:
> 1. If the creator name is not set yet (ie null) my program works
> 2. If the creator name is already set, the ODF toolkit throws a
> NullPointerException during save().
> I am attaching a test case and a one page odp file.
> Kelvin
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira