Program: 24078
Project: 24078
Buggy source:
@Override public XhtmlGeneratorAdornerState getState(XhtmlGenerator ref,XhtmlGeneratorAdornerState state,Element node) throws Exception {
  if (state == null) {
    if (node == null)     return new ExampleAdornerState(State.Unknown,"String_Node_Str",null,"String_Node_Str","String_Node_Str");
 else     if (definitions.hasResource(node.getLocalName()))     return new ExampleAdornerState(State.Element,node.getLocalName(),definitions.getResourceByName(node.getLocalName()).getRoot(),"String_Node_Str","String_Node_Str");
 else     return new ExampleAdornerState(State.Unknown,"String_Node_Str",null,"String_Node_Str","String_Node_Str");
  }
 else {
    ExampleAdornerState s=(ExampleAdornerState)state;
    if (s.getState() == State.Element) {
      String p=s.path + "String_Node_Str" + node.getNodeName();
      ElementDefn e=s.getDefinition().getElementByName(node.getLocalName(),true,definitions,"String_Node_Str");
      if (e == null && definitions.hasElementDefn(s.getDefinition().typeCode())) {
        ElementDefn t=definitions.getElementDefn(s.getDefinition().typeCode());
        while (t != null && e == null) {
          e=t.getElementByName(node.getLocalName(),true,definitions,"String_Node_Str");
          if (e != null)           p=t.getName() + "String_Node_Str" + e.getName();
 else           if (definitions.hasElementDefn(t.typeCode()))           t=definitions.getElementDefn(t.typeCode());
 else           t=null;
        }
      }
 else       if (e != null)       p=s.path + "String_Node_Str" + e.getName();
      if (e == null)       return new ExampleAdornerState(State.Unknown,s.path,null,"String_Node_Str","String_Node_Str");
      if (!e.isBaseResourceElement() && e.typeCode().contains("String_Node_Str"))       return new ExampleAdornerState(State.Reference,p,e,"String_Node_Str","String_Node_Str");
 else       if (!e.isBaseResourceElement() && e.typeCode().equals("String_Node_Str"))       return new ExampleAdornerState(State.Reference,p,e,"String_Node_Str","String_Node_Str");
 else       return new ExampleAdornerState(State.Element,p,e,"String_Node_Str","String_Node_Str");
    }
 else     if (s.getState() == State.Reference) {
      if (node.getLocalName().equals("String_Node_Str")) {
        String type=extractType(node.getAttribute("String_Node_Str"));
        String id=extractId(node.getAttribute("String_Node_Str"),type);
        if (id == null)         return new ExampleAdornerState(State.Element,s.path + "String_Node_Str",null,"String_Node_Str","String_Node_Str");
        ResourceDefn r=definitions.getResourceByName(type);
        if (r == null)         throw new Exception("String_Node_Str" + type);
        for (        Example e : r.getExamples()) {
          if (id.equals(e.getId()))           return new ExampleAdornerState(State.Reference,s.path + "String_Node_Str",s.getDefinition(),"String_Node_Str" + prefix + e.getTitle()+ "String_Node_Str","String_Node_Str");
          if (e.getXml() != null && e.getXml().getDocumentElement().getLocalName().equals("String_Node_Str")) {
            List<Element> entries=new ArrayList<Element>();
            XMLUtil.getNamedChildren(e.getXml().getDocumentElement(),"String_Node_Str",entries);
            String url="String_Node_Str" + type + "String_Node_Str"+ id;
            for (            Element c : entries) {
              String t=XMLUtil.getNamedChild(c,"String_Node_Str").getAttribute("String_Node_Str");
              if (url.equals(t))               return new ExampleAdornerState(State.Reference,s.path + "String_Node_Str",s.getDefinition(),"String_Node_Str" + prefix + e.getTitle()+ "String_Node_Str"+ id+ "String_Node_Str","String_Node_Str");
            }
          }
        }
        return new ExampleAdornerState(State.Reference,s.path + "String_Node_Str",s.getDefinition(),"String_Node_Str","String_Node_Str");
      }
 else       return new ExampleAdornerState(State.Reference,s.path,s.getDefinition(),"String_Node_Str","String_Node_Str");
    }
 else     return new ExampleAdornerState(State.Unknown,s.path,null,"String_Node_Str","String_Node_Str");
  }
}

Fixed version (ground truth):
@Override public XhtmlGeneratorAdornerState getState(XhtmlGenerator ref,XhtmlGeneratorAdornerState state,Element node) throws Exception {
  if (state == null) {
    if (node == null)     return new ExampleAdornerState(State.Unknown,"String_Node_Str",null,"String_Node_Str","String_Node_Str");
 else     if (definitions.hasResource(node.getLocalName()))     return new ExampleAdornerState(State.Element,node.getLocalName(),definitions.getResourceByName(node.getLocalName()).getRoot(),"String_Node_Str","String_Node_Str");
 else     return new ExampleAdornerState(State.Unknown,"String_Node_Str",null,"String_Node_Str","String_Node_Str");
  }
 else {
    ExampleAdornerState s=(ExampleAdornerState)state;
    if (s.getState() == State.Element) {
      if (s.definition.typeCode().equals("String_Node_Str") && (s.path.endsWith("String_Node_Str") || s.path.endsWith("String_Node_Str")) && definitions.isResource(node.getNodeName()))       return new ExampleAdornerState(State.Element,s.path,definitions.getResourceByName(node.getNodeName()).getRoot(),"String_Node_Str","String_Node_Str");
      String p=s.path + "String_Node_Str" + node.getNodeName();
      ElementDefn e=s.getDefinition().getElementByName(node.getLocalName(),true,definitions,"String_Node_Str");
      if (e == null && definitions.hasElementDefn(s.getDefinition().typeCode())) {
        ElementDefn t=definitions.getElementDefn(s.getDefinition().typeCode());
        while (t != null && e == null) {
          e=t.getElementByName(node.getLocalName(),true,definitions,"String_Node_Str");
          if (e != null)           p=t.getName() + "String_Node_Str" + e.getName();
 else           if (definitions.hasElementDefn(t.typeCode()))           t=definitions.getElementDefn(t.typeCode());
 else           t=null;
        }
      }
 else       if (e != null)       p=s.path + "String_Node_Str" + e.getName();
      if (e == null)       return new ExampleAdornerState(State.Unknown,s.path,null,"String_Node_Str","String_Node_Str");
      if (!e.isBaseResourceElement() && e.typeCode().contains("String_Node_Str"))       return new ExampleAdornerState(State.Reference,p,e,"String_Node_Str","String_Node_Str");
 else       if (!e.isBaseResourceElement() && e.typeCode().equals("String_Node_Str"))       return new ExampleAdornerState(State.Reference,p,e,"String_Node_Str","String_Node_Str");
 else       return new ExampleAdornerState(State.Element,p,e,"String_Node_Str","String_Node_Str");
    }
 else     if (s.getState() == State.Reference) {
      if (node.getLocalName().equals("String_Node_Str")) {
        String type=extractType(node.getAttribute("String_Node_Str"));
        String id=extractId(node.getAttribute("String_Node_Str"),type);
        if (id == null)         return new ExampleAdornerState(State.Element,s.path + "String_Node_Str",null,"String_Node_Str","String_Node_Str");
        ResourceDefn r=definitions.getResourceByName(type);
        if (r == null)         throw new Exception("String_Node_Str" + type);
        for (        Example e : r.getExamples()) {
          if (id.equals(e.getId()))           return new ExampleAdornerState(State.Reference,s.path + "String_Node_Str",s.getDefinition(),"String_Node_Str" + prefix + e.getTitle()+ "String_Node_Str","String_Node_Str");
          if (e.getXml() != null && e.getXml().getDocumentElement().getLocalName().equals("String_Node_Str")) {
            List<Element> entries=new ArrayList<Element>();
            XMLUtil.getNamedChildren(e.getXml().getDocumentElement(),"String_Node_Str",entries);
            String url="String_Node_Str" + type + "String_Node_Str"+ id;
            for (            Element c : entries) {
              String t=XMLUtil.getNamedChild(c,"String_Node_Str").getAttribute("String_Node_Str");
              if (url.equals(t))               return new ExampleAdornerState(State.Reference,s.path + "String_Node_Str",s.getDefinition(),"String_Node_Str" + prefix + e.getTitle()+ "String_Node_Str"+ id+ "String_Node_Str","String_Node_Str");
            }
          }
        }
        return new ExampleAdornerState(State.Reference,s.path + "String_Node_Str",s.getDefinition(),"String_Node_Str","String_Node_Str");
      }
 else       return new ExampleAdornerState(State.Reference,s.path,s.getDefinition(),"String_Node_Str","String_Node_Str");
    }
 else     return new ExampleAdornerState(State.Unknown,s.path,null,"String_Node_Str","String_Node_Str");
  }
}