Program: 16094
Project: 16094
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(message("String_Node_Str",root));
  }
 else {
    final String ns=IDOMs.getRequiredElementValue(root,"String_Node_Str");
    final String deviceType=IDOMs.getRequiredElementValue(root,"String_Node_Str");
    PageRenderer pageRenderer=(PageRenderer)locateClass(IDOMs.getRequiredElementValue(root,"String_Node_Str"),PageRenderer.class).newInstance();
    final List<String> exts=parseExtensions(root);
    if (exts.isEmpty())     throw new UiException(message("String_Node_Str" + lang,root));
    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 (  Element el : root.getElements("String_Node_Str")) {
    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 (  Element el : root.getElements("String_Node_Str")) {
    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");
    String mergeTo=el.getAttributeValue("String_Node_Str");
    final boolean merge=mergeTo != null && !"String_Node_Str".equals(mergeTo);
    if (merge && "String_Node_Str".equals(mergeTo))     mergeTo="String_Node_Str";
    final String lazyTo=el.getAttributeValue("String_Node_Str");
    final boolean lazy=lazyTo != null && !"String_Node_Str".equals(lazyTo) && pkg != null && pkg.length() > 0;
    final String lazyPkg=pkg;
    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.unmergeJavaScriptPackage(pkg,mergeTo);
      }
 else {
        langdef.mergeJavaScriptPackage(pkg,mergeTo);
      }
      continue;
    }
 else     if (src != null && src.length() > 0) {
      if (ctn != null && ctn.length() > 0)       throw new UiException(message("String_Node_Str",el));
      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;
    }
    if (lazy)     langdef.addLazyPackage(lazyPkg);
 else     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(message("String_Node_Str",el));
      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(message("String_Node_Str",el));
    }
    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(message("String_Node_Str",attr));
    }
    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<? extends Component> cls=null;
    if (clsnm != null) {
      if (clsnm.length() > 0) {
        noEL("String_Node_Str",clsnm,el);
        try {
          cls=locateClass(clsnm,Component.class);
        }
 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(message("String_Node_Str",el));
      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(message("String_Node_Str",el));
      compdef=cls != null ? new ComponentDefinitionImpl(langdef,null,name,cls) : new ComponentDefinitionImpl(langdef,null,name,clsnm);
      compdef.setDeclarationURL(url);
      langdef.addComponentDefinition(compdef);
    }
    parseTextAs(compdef,el.getElement("String_Node_Str"));
    String s=el.getElementValue("String_Node_Str",true);
    compdef.setBlankPreserved((s != null && !"String_Node_Str".equals(s)));
    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(message("String_Node_Str",root));
  }
 else {
    final String ns=IDOMs.getRequiredElementValue(root,"String_Node_Str");
    final String deviceType=IDOMs.getRequiredElementValue(root,"String_Node_Str");
    PageRenderer pageRenderer=(PageRenderer)locateClass(IDOMs.getRequiredElementValue(root,"String_Node_Str"),PageRenderer.class).newInstance();
    final List<String> exts=parseExtensions(root);
    if (exts.isEmpty())     throw new UiException(message("String_Node_Str" + lang,root));
    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 (  Element el : root.getElements("String_Node_Str")) {
    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 (  Element el : root.getElements("String_Node_Str")) {
    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");
    String mergeTo=el.getAttributeValue("String_Node_Str");
    final boolean merge=mergeTo != null && !"String_Node_Str".equals(mergeTo);
    if (merge && "String_Node_Str".equals(mergeTo))     mergeTo="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.unmergeJavaScriptPackage(pkg,mergeTo);
      }
 else {
        langdef.mergeJavaScriptPackage(pkg,mergeTo);
      }
      continue;
    }
 else     if (src != null && src.length() > 0) {
      if (ctn != null && ctn.length() > 0)       throw new UiException(message("String_Node_Str",el));
      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(message("String_Node_Str",el));
      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(message("String_Node_Str",el));
    }
    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(message("String_Node_Str",attr));
    }
    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<? extends Component> cls=null;
    if (clsnm != null) {
      if (clsnm.length() > 0) {
        noEL("String_Node_Str",clsnm,el);
        try {
          cls=locateClass(clsnm,Component.class);
        }
 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(message("String_Node_Str",el));
      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(message("String_Node_Str",el));
      compdef=cls != null ? new ComponentDefinitionImpl(langdef,null,name,cls) : new ComponentDefinitionImpl(langdef,null,name,clsnm);
      compdef.setDeclarationURL(url);
      langdef.addComponentDefinition(compdef);
    }
    parseTextAs(compdef,el.getElement("String_Node_Str"));
    String s=el.getElementValue("String_Node_Str",true);
    compdef.setBlankPreserved((s != null && !"String_Node_Str".equals(s)));
    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);
  }
}