I discovered today that under certain circumstances you can create an
OMElementImpl that will go into an infinte loop if you call
getFirstElement(); The specific example I found is if you create an
OMElement via the SAXOMBuilder and pass the SAXOMBuilder and
incomplete/malformed series of events (example code below). The workaround
is to check isComplete() before calling getFirstElement(), but it seems like
there should be some other way to avoid this condition.
It almost seems like there should just be different implementations of
OMElement. one that would be for programmatically built, and one for
elements constructed via an underlying stream - seems like that would
simplify a lot of the code.
package axiomtest;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.builder.SAXOMBuilder;
import org.xml.sax.Attributes;
public class InfinteLoopDemo {
public static void main(String[] args) throws Exception{
SAXOMBuilder builder = new SAXOMBuilder();
builder.startDocument();
builder.startElement("http://test.com", "test",
"test:http://test.com", new Attributes(){
public int getIndex(String uri, String localName) {
// TODO Auto-generated method stub
return 0;
}
public int getIndex(String qName) {
// TODO Auto-generated method stub
return 0;
}
public int getLength() {
// TODO Auto-generated method stub
return 0;
}
public String getLocalName(int index) {
// TODO Auto-generated method stub
return null;
}
public String getQName(int index) {
// TODO Auto-generated method stub
return null;
}
public String getType(int index) {
// TODO Auto-generated method stub
return null;
}
public String getType(String uri, String localName) {
// TODO Auto-generated method stub
return null;
}
public String getType(String qName) {
// TODO Auto-generated method stub
return null;
}
public String getURI(int index) {
// TODO Auto-generated method stub
return null;
}
public String getValue(int index) {
// TODO Auto-generated method stub
return null;
}
public String getValue(String uri, String localName) {
// TODO Auto-generated method stub
return null;
}
public String getValue(String qName) {
// TODO Auto-generated method stub
return null;
}
});
OMElement root = builder.getRootElement();
OMElement firstChild = root.getFirstElement(); //infinite loop here
System.out.println("First child is: " + firstChild);
}
}
Ryan Nelsestuen