Program: 16257
Project: 16257
Buggy source:
private static void parseLang(Document doc,Locator locator,URL url,boolean addon) throws Exception {
  final Element root=doc.getRootElement();
  final String lang=IDOMs.getRequiredElementValue(root,"String_Node_Str");
  final LanguageDefinition langdef;
  final Device device;
  if (addon) {
    if (log.debugable())     log.debug("String_Node_Str" + lang + "String_Node_Str"+ root.getElementValue("String_Node_Str",true));
    langdef=LanguageDefinition.lookup(lang);
    device=Devices.getDevice(langdef.getDeviceType());
    if (root.getElement("String_Node_Str") != null)     throw new UiException("String_Node_Str");
  }
 else {
    final String ns=(String)IDOMs.getRequiredElementValue(root,"String_Node_Str");
    final String deviceType=(String)IDOMs.getRequiredElementValue(root,"String_Node_Str");
    PageRenderer pageRenderer=(PageRenderer)locateClass(IDOMs.getRequiredElementValue(root,"String_Node_Str")).newInstance();
    final List exts=parseExtensions(root);
    if (exts.isEmpty())     throw new UiException("String_Node_Str" + lang);
    String ignoreCase=root.getElementValue("String_Node_Str",true);
    String bNative=root.getElementValue("String_Node_Str",true);
    langdef=new LanguageDefinition(deviceType,lang,ns,exts,pageRenderer,"String_Node_Str".equals(ignoreCase),"String_Node_Str".equals(bNative),locator);
    device=Devices.getDevice(deviceType);
  }
  parsePI(langdef,doc);
  parseLabelTemplate(langdef,root);
  parseDynamicTag(langdef,root);
  parseMacroTemplate(langdef,root);
  parseNativeTemplate(langdef,root);
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    final String nm=IDOMs.getRequiredElementValue(el,"String_Node_Str");
    final String val=IDOMs.getRequiredElementValue(el,"String_Node_Str");
    Library.setProperty(nm,val);
  }
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    final String nm=IDOMs.getRequiredElementValue(el,"String_Node_Str");
    final String val=IDOMs.getRequiredElementValue(el,"String_Node_Str");
    System.setProperty(nm,val);
  }
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    String src=el.getAttributeValue("String_Node_Str"), pkg=el.getAttributeValue("String_Node_Str");
    final boolean merge="String_Node_Str".equals(el.getAttributeValue("String_Node_Str"));
    final boolean ondemand="String_Node_Str".equals(el.getAttributeValue("String_Node_Str"));
    if (pkg != null) {
      if (src != null)       log.warning("String_Node_Str" + el.getLocator());
      if (!ondemand && !merge) {
        src="String_Node_Str" + device.packageToPath(pkg);
        pkg=null;
      }
    }
    final String ctn=el.getText(true);
    final JavaScript js;
    if (pkg != null && pkg.length() > 0) {
      if (ondemand) {
        langdef.removeJavaScript("String_Node_Str" + device.packageToPath(pkg));
        langdef.removeMergeJavaScriptPackage(pkg);
      }
 else {
        langdef.addMergeJavaScriptPackage(pkg);
      }
      continue;
    }
 else     if (src != null && src.length() > 0) {
      if (ctn != null && ctn.length() > 0)       throw new UiException("String_Node_Str" + el.getLocator());
      final String charset=el.getAttributeValue("String_Node_Str");
      js=new JavaScript(src,charset);
    }
 else     if (ctn != null && ctn.length() > 0) {
      js=new JavaScript(ctn);
    }
 else {
      log.warning("String_Node_Str" + el.getLocator());
      continue;
    }
    langdef.addJavaScript(js);
  }
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    langdef.addJavaScriptModule(IDOMs.getRequiredAttributeValue(el,"String_Node_Str"),IDOMs.getRequiredAttributeValue(el,"String_Node_Str"));
  }
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    final String href=el.getAttributeValue("String_Node_Str");
    final String ctn=el.getText(true);
    final StyleSheet ss;
    if (href != null && href.length() > 0) {
      if (ctn != null && ctn.length() > 0)       throw new UiException("String_Node_Str" + el.getLocator());
      ss=new StyleSheet(href,el.getAttributeValue("String_Node_Str"),el.getAttributeValue("String_Node_Str"),false);
    }
 else     if (ctn != null && ctn.length() > 0) {
      ss=new StyleSheet(ctn,el.getAttributeValue("String_Node_Str"),el.getAttributeValue("String_Node_Str"),true);
    }
 else {
      throw new UiException("String_Node_Str" + el.getLocator());
    }
    langdef.addStyleSheet(ss);
  }
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    final String zslang;
    final Attribute attr=el.getAttributeItem("String_Node_Str");
    if (attr == null) {
      zslang="String_Node_Str";
    }
 else {
      zslang=attr.getValue();
      if (zslang == null || zslang.length() == 0)       throw new UiException("String_Node_Str" + attr.getLocator());
    }
    final String s=el.getText(true);
    final String eachTime=el.getAttributeValue("String_Node_Str");
    if ("String_Node_Str".equals(eachTime))     langdef.addEachTimeScript(zslang,s);
 else     langdef.addInitScript(zslang,s);
  }
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    final String name=IDOMs.getRequiredElementValue(el,"String_Node_Str");
    String clsnm=el.getElementValue("String_Node_Str",true);
    Class cls=null;
    if (clsnm != null) {
      if (clsnm.length() > 0) {
        noEL("String_Node_Str",clsnm,el);
        try {
          cls=locateClass(clsnm);
        }
 catch (        Throwable ex) {
          log.warning("String_Node_Str" + name + "String_Node_Str"+ clsnm+ "String_Node_Str"+ ex.getClass().getName()+ "String_Node_Str"+ ex.getMessage()+ (ex instanceof NoClassDefFoundError ? "String_Node_Str" : "String_Node_Str" + el.getLocator()));
          log.debug(ex);
        }
      }
 else {
        clsnm=null;
      }
    }
    final String macroURI=el.getElementValue("String_Node_Str",true);
    final ComponentDefinitionImpl compdef;
    boolean extend=false;
    if (macroURI != null && macroURI.length() != 0) {
      if (log.finerable())       log.finer("String_Node_Str" + name);
      final String inline=el.getElementValue("String_Node_Str",true);
      compdef=(ComponentDefinitionImpl)langdef.getMacroDefinition(name,macroURI,"String_Node_Str".equals(inline),null);
      if (cls != null)       compdef.setImplementationClass(cls);
 else       if (clsnm != null)       compdef.setImplementationClass(clsnm);
      compdef.setDeclarationURL(url);
      langdef.addComponentDefinition(compdef);
    }
 else     if (el.getElement("String_Node_Str") != null) {
      extend=true;
      final String extnm=el.getElementValue("String_Node_Str",true);
      if (log.finerable())       log.finer("String_Node_Str" + name + "String_Node_Str"+ extnm);
      final ComponentDefinition ref=langdef.getComponentDefinitionIfAny(extnm);
      if (ref == null) {
        log.warning("String_Node_Str" + name + "String_Node_Str"+ extnm+ "String_Node_Str"+ el.getLocator());
        continue;
      }
      if (ref.isMacro())       throw new UiException("String_Node_Str" + el.getLocator());
      if (extnm.equals(name)) {
        compdef=(ComponentDefinitionImpl)ref;
      }
 else {
        compdef=(ComponentDefinitionImpl)ref.clone(ref.getLanguageDefinition(),name);
        compdef.setDeclarationURL(url);
      }
      if (cls != null)       compdef.setImplementationClass(cls);
 else       if (clsnm != null)       compdef.setImplementationClass(clsnm);
      langdef.addComponentDefinition(compdef);
    }
 else {
      if (log.finerable())       log.finer("String_Node_Str" + name);
      if (cls == null && clsnm == null)       throw new UiException("String_Node_Str" + el.getLocator());
      compdef=cls != null ? new ComponentDefinitionImpl(langdef,null,name,cls) : new ComponentDefinitionImpl(langdef,null,name,clsnm);
      compdef.setDeclarationURL(url);
      langdef.addComponentDefinition(compdef);
    }
    String s=el.getElementValue("String_Node_Str",true);
    if (s != null) {
      noEL("String_Node_Str",s,el);
      compdef.setTextAs(s);
    }
    s=el.getElementValue("String_Node_Str",true);
    if (s != null && !"String_Node_Str".equals(s))     compdef.setBlankPreserved(true);
    String wgtnm=el.getElementValue("String_Node_Str",true);
    WidgetDefinition wgtdef=null;
    if (wgtnm == null && extend)     wgtnm=compdef.getDefaultWidgetClass(null);
    if (wgtnm != null) {
      if (!withEL(wgtnm))       wgtdef=getWidgetDefinition(langdef,compdef,wgtnm);
      compdef.setDefaultWidgetClass(wgtnm);
    }
    s=el.getElementValue("String_Node_Str",true);
    if (s == null)     s=el.getElementValue("String_Node_Str",true);
    compdef.setApply(s);
    for (Iterator i=el.getElements("String_Node_Str").iterator(); i.hasNext(); ) {
      final Element e=(Element)i.next();
      final String nm=IDOMs.getRequiredElementValue(e,"String_Node_Str");
      final String moldURI=e.getElementValue("String_Node_Str",true);
      String cssURI=e.getElementValue("String_Node_Str",true);
      final String wn=e.getElementValue("String_Node_Str",true);
      noEL("String_Node_Str",moldURI,e);
      noEL("String_Node_Str",cssURI,e);
      compdef.addMold(nm,wn != null ? wn : wgtnm);
      WidgetDefinition wd=wn == null ? wgtdef : withEL(wn) ? null : getWidgetDefinition(langdef,compdef,wn);
      if (moldURI != null) {
        if (wd != null)         wd.addMold(nm,moldURI);
 else         log.error("String_Node_Str" + nm + "String_Node_Str"+ name+ "String_Node_Str"+ ((wn != null && withEL(wn)) || (wgtnm != null && withEL(wgtnm)) ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str"+ e.getLocator());
      }
      if (cssURI != null && cssURI.length() > 0) {
        final char cc=cssURI.charAt(0);
        if (cc != '/' && cc != '~') {
          String n=wn != null ? wn : wgtnm;
          if (!withEL(n)) {
            int k=n.lastIndexOf('.');
            cssURI="String_Node_Str" + device.toAbsolutePath(n.substring(0,k).replace('.','/') + '/' + cssURI);
          }
 else {
            log.error("String_Node_Str" + e.getLocator());
          }
        }
        langdef.addCSSURI(cssURI);
      }
    }
    for (Iterator e=parseCustAttrs(el).entrySet().iterator(); e.hasNext(); ) {
      final Map.Entry me=(Map.Entry)e.next();
      compdef.addCustomAttribute((String)me.getKey(),(String)me.getValue());
    }
    for (Iterator e=parseProps(el).entrySet().iterator(); e.hasNext(); ) {
      final Map.Entry me=(Map.Entry)e.next();
      compdef.addProperty((String)me.getKey(),(String)me.getValue());
    }
    parseAnnots(compdef,el);
  }
}

Fixed version (ground truth):
private static void parseLang(Document doc,Locator locator,URL url,boolean addon) throws Exception {
  final Element root=doc.getRootElement();
  final String lang=IDOMs.getRequiredElementValue(root,"String_Node_Str");
  final LanguageDefinition langdef;
  final Device device;
  if (addon) {
    if (log.debugable())     log.debug("String_Node_Str" + lang + "String_Node_Str"+ root.getElementValue("String_Node_Str",true));
    langdef=LanguageDefinition.lookup(lang);
    device=Devices.getDevice(langdef.getDeviceType());
    if (root.getElement("String_Node_Str") != null)     throw new UiException("String_Node_Str");
  }
 else {
    final String ns=(String)IDOMs.getRequiredElementValue(root,"String_Node_Str");
    final String deviceType=(String)IDOMs.getRequiredElementValue(root,"String_Node_Str");
    PageRenderer pageRenderer=(PageRenderer)locateClass(IDOMs.getRequiredElementValue(root,"String_Node_Str")).newInstance();
    final List exts=parseExtensions(root);
    if (exts.isEmpty())     throw new UiException("String_Node_Str" + lang);
    String ignoreCase=root.getElementValue("String_Node_Str",true);
    String bNative=root.getElementValue("String_Node_Str",true);
    langdef=new LanguageDefinition(deviceType,lang,ns,exts,pageRenderer,"String_Node_Str".equals(ignoreCase),"String_Node_Str".equals(bNative),locator);
    device=Devices.getDevice(deviceType);
  }
  parsePI(langdef,doc);
  parseLabelTemplate(langdef,root);
  parseDynamicTag(langdef,root);
  parseMacroTemplate(langdef,root);
  parseNativeTemplate(langdef,root);
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    final String clsname=el.getText().trim();
    if (Strings.isEmpty(clsname))     throw new UiException("String_Node_Str" + lang);
    MessageLoader msgLoader=(MessageLoader)locateClass(clsname).newInstance();
    langdef.addMessageLoader(msgLoader);
  }
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    final String nm=IDOMs.getRequiredElementValue(el,"String_Node_Str");
    final String val=IDOMs.getRequiredElementValue(el,"String_Node_Str");
    Library.setProperty(nm,val);
  }
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    final String nm=IDOMs.getRequiredElementValue(el,"String_Node_Str");
    final String val=IDOMs.getRequiredElementValue(el,"String_Node_Str");
    System.setProperty(nm,val);
  }
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    String src=el.getAttributeValue("String_Node_Str"), pkg=el.getAttributeValue("String_Node_Str");
    final boolean merge="String_Node_Str".equals(el.getAttributeValue("String_Node_Str"));
    final boolean ondemand="String_Node_Str".equals(el.getAttributeValue("String_Node_Str"));
    if (pkg != null) {
      if (src != null)       log.warning("String_Node_Str" + el.getLocator());
      if (!ondemand && !merge) {
        src="String_Node_Str" + device.packageToPath(pkg);
        pkg=null;
      }
    }
    final String ctn=el.getText(true);
    final JavaScript js;
    if (pkg != null && pkg.length() > 0) {
      if (ondemand) {
        langdef.removeJavaScript("String_Node_Str" + device.packageToPath(pkg));
        langdef.removeMergeJavaScriptPackage(pkg);
      }
 else {
        langdef.addMergeJavaScriptPackage(pkg);
      }
      continue;
    }
 else     if (src != null && src.length() > 0) {
      if (ctn != null && ctn.length() > 0)       throw new UiException("String_Node_Str" + el.getLocator());
      final String charset=el.getAttributeValue("String_Node_Str");
      js=new JavaScript(src,charset);
    }
 else     if (ctn != null && ctn.length() > 0) {
      js=new JavaScript(ctn);
    }
 else {
      log.warning("String_Node_Str" + el.getLocator());
      continue;
    }
    langdef.addJavaScript(js);
  }
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    langdef.addJavaScriptModule(IDOMs.getRequiredAttributeValue(el,"String_Node_Str"),IDOMs.getRequiredAttributeValue(el,"String_Node_Str"));
  }
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    final String href=el.getAttributeValue("String_Node_Str");
    final String ctn=el.getText(true);
    final StyleSheet ss;
    if (href != null && href.length() > 0) {
      if (ctn != null && ctn.length() > 0)       throw new UiException("String_Node_Str" + el.getLocator());
      ss=new StyleSheet(href,el.getAttributeValue("String_Node_Str"),el.getAttributeValue("String_Node_Str"),false);
    }
 else     if (ctn != null && ctn.length() > 0) {
      ss=new StyleSheet(ctn,el.getAttributeValue("String_Node_Str"),el.getAttributeValue("String_Node_Str"),true);
    }
 else {
      throw new UiException("String_Node_Str" + el.getLocator());
    }
    langdef.addStyleSheet(ss);
  }
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    final String zslang;
    final Attribute attr=el.getAttributeItem("String_Node_Str");
    if (attr == null) {
      zslang="String_Node_Str";
    }
 else {
      zslang=attr.getValue();
      if (zslang == null || zslang.length() == 0)       throw new UiException("String_Node_Str" + attr.getLocator());
    }
    final String s=el.getText(true);
    final String eachTime=el.getAttributeValue("String_Node_Str");
    if ("String_Node_Str".equals(eachTime))     langdef.addEachTimeScript(zslang,s);
 else     langdef.addInitScript(zslang,s);
  }
  for (Iterator it=root.getElements("String_Node_Str").iterator(); it.hasNext(); ) {
    final Element el=(Element)it.next();
    final String name=IDOMs.getRequiredElementValue(el,"String_Node_Str");
    String clsnm=el.getElementValue("String_Node_Str",true);
    Class cls=null;
    if (clsnm != null) {
      if (clsnm.length() > 0) {
        noEL("String_Node_Str",clsnm,el);
        try {
          cls=locateClass(clsnm);
        }
 catch (        Throwable ex) {
          log.warning("String_Node_Str" + name + "String_Node_Str"+ clsnm+ "String_Node_Str"+ ex.getClass().getName()+ "String_Node_Str"+ ex.getMessage()+ (ex instanceof NoClassDefFoundError ? "String_Node_Str" : "String_Node_Str" + el.getLocator()));
          log.debug(ex);
        }
      }
 else {
        clsnm=null;
      }
    }
    final String macroURI=el.getElementValue("String_Node_Str",true);
    final ComponentDefinitionImpl compdef;
    boolean extend=false;
    if (macroURI != null && macroURI.length() != 0) {
      if (log.finerable())       log.finer("String_Node_Str" + name);
      final String inline=el.getElementValue("String_Node_Str",true);
      compdef=(ComponentDefinitionImpl)langdef.getMacroDefinition(name,macroURI,"String_Node_Str".equals(inline),null);
      if (cls != null)       compdef.setImplementationClass(cls);
 else       if (clsnm != null)       compdef.setImplementationClass(clsnm);
      compdef.setDeclarationURL(url);
      langdef.addComponentDefinition(compdef);
    }
 else     if (el.getElement("String_Node_Str") != null) {
      extend=true;
      final String extnm=el.getElementValue("String_Node_Str",true);
      if (log.finerable())       log.finer("String_Node_Str" + name + "String_Node_Str"+ extnm);
      final ComponentDefinition ref=langdef.getComponentDefinitionIfAny(extnm);
      if (ref == null) {
        log.warning("String_Node_Str" + name + "String_Node_Str"+ extnm+ "String_Node_Str"+ el.getLocator());
        continue;
      }
      if (ref.isMacro())       throw new UiException("String_Node_Str" + el.getLocator());
      if (extnm.equals(name)) {
        compdef=(ComponentDefinitionImpl)ref;
      }
 else {
        compdef=(ComponentDefinitionImpl)ref.clone(ref.getLanguageDefinition(),name);
        compdef.setDeclarationURL(url);
      }
      if (cls != null)       compdef.setImplementationClass(cls);
 else       if (clsnm != null)       compdef.setImplementationClass(clsnm);
      langdef.addComponentDefinition(compdef);
    }
 else {
      if (log.finerable())       log.finer("String_Node_Str" + name);
      if (cls == null && clsnm == null)       throw new UiException("String_Node_Str" + el.getLocator());
      compdef=cls != null ? new ComponentDefinitionImpl(langdef,null,name,cls) : new ComponentDefinitionImpl(langdef,null,name,clsnm);
      compdef.setDeclarationURL(url);
      langdef.addComponentDefinition(compdef);
    }
    String s=el.getElementValue("String_Node_Str",true);
    if (s != null) {
      noEL("String_Node_Str",s,el);
      compdef.setTextAs(s);
    }
    s=el.getElementValue("String_Node_Str",true);
    if (s != null && !"String_Node_Str".equals(s))     compdef.setBlankPreserved(true);
    String wgtnm=el.getElementValue("String_Node_Str",true);
    WidgetDefinition wgtdef=null;
    if (wgtnm == null && extend)     wgtnm=compdef.getDefaultWidgetClass(null);
    if (wgtnm != null) {
      if (!withEL(wgtnm))       wgtdef=getWidgetDefinition(langdef,compdef,wgtnm);
      compdef.setDefaultWidgetClass(wgtnm);
    }
    s=el.getElementValue("String_Node_Str",true);
    if (s == null)     s=el.getElementValue("String_Node_Str",true);
    compdef.setApply(s);
    for (Iterator i=el.getElements("String_Node_Str").iterator(); i.hasNext(); ) {
      final Element e=(Element)i.next();
      final String nm=IDOMs.getRequiredElementValue(e,"String_Node_Str");
      final String moldURI=e.getElementValue("String_Node_Str",true);
      String cssURI=e.getElementValue("String_Node_Str",true);
      final String wn=e.getElementValue("String_Node_Str",true);
      noEL("String_Node_Str",moldURI,e);
      noEL("String_Node_Str",cssURI,e);
      compdef.addMold(nm,wn != null ? wn : wgtnm);
      WidgetDefinition wd=wn == null ? wgtdef : withEL(wn) ? null : getWidgetDefinition(langdef,compdef,wn);
      if (moldURI != null) {
        if (wd != null)         wd.addMold(nm,moldURI);
 else         log.error("String_Node_Str" + nm + "String_Node_Str"+ name+ "String_Node_Str"+ ((wn != null && withEL(wn)) || (wgtnm != null && withEL(wgtnm)) ? "String_Node_Str" : "String_Node_Str")+ "String_Node_Str"+ e.getLocator());
      }
      if (cssURI != null && cssURI.length() > 0) {
        final char cc=cssURI.charAt(0);
        if (cc != '/' && cc != '~') {
          String n=wn != null ? wn : wgtnm;
          if (!withEL(n)) {
            int k=n.lastIndexOf('.');
            cssURI="String_Node_Str" + device.toAbsolutePath(n.substring(0,k).replace('.','/') + '/' + cssURI);
          }
 else {
            log.error("String_Node_Str" + e.getLocator());
          }
        }
        langdef.addCSSURI(cssURI);
      }
    }
    for (Iterator e=parseCustAttrs(el).entrySet().iterator(); e.hasNext(); ) {
      final Map.Entry me=(Map.Entry)e.next();
      compdef.addCustomAttribute((String)me.getKey(),(String)me.getValue());
    }
    for (Iterator e=parseProps(el).entrySet().iterator(); e.hasNext(); ) {
      final Map.Entry me=(Map.Entry)e.next();
      compdef.addProperty((String)me.getKey(),(String)me.getValue());
    }
    parseAnnots(compdef,el);
  }
}