Program: 117045
Project: 117045
Buggy source:
private AppConfig(Context context){
  this.context=context;
  InputStream is=null;
  InputStream jsonIs=null;
  try {
    if (fileForOTAconfig().exists()) {
      InputStream otaIS=null;
      try {
        otaIS=new BufferedInputStream(new FileInputStream(fileForOTAconfig()));
        ByteArrayOutputStream baos=new ByteArrayOutputStream();
        IOUtils.copy(otaIS,baos);
        baos.close();
        this.json=new JSONObject(baos.toString("String_Node_Str"));
      }
 catch (      Exception e) {
        Log.e(TAG,e.getMessage(),e);
        IOUtils.close(otaIS);
      }
    }
    if (this.json == null) {
      jsonIs=context.getAssets().open("String_Node_Str");
      ByteArrayOutputStream baos=new ByteArrayOutputStream();
      IOUtils.copy(jsonIs,baos);
      IOUtils.close(baos);
      this.json=new JSONObject(baos.toString("String_Node_Str"));
    }
    this.menus=new HashMap<String,JSONArray>();
    this.loginDetectRegexes=new ArrayList<Pattern>();
    this.loginDetectLocations=new ArrayList<JSONObject>();
    this.navStructureLevelsRegex=new ArrayList<Pattern>();
    this.navStructureLevels=new ArrayList<Integer>();
    this.navTitles=new ArrayList<HashMap<String,Object>>();
    this.regexInternalExternal=new ArrayList<Pattern>();
    this.regexIsInternal=new ArrayList<Boolean>();
    JSONObject general=this.json.optJSONObject("String_Node_Str");
    if (general != null) {
      this.initialUrl=optString(general,"String_Node_Str");
      initialHost=Uri.parse(this.initialUrl).getHost();
      if (initialHost.startsWith("String_Node_Str")) {
        initialHost=initialHost.substring("String_Node_Str".length());
      }
      this.appName=optString(general,"String_Node_Str");
      String userAgentAdd=optString(general,"String_Node_Str");
      if (userAgentAdd == null)       userAgentAdd="String_Node_Str";
      WebView wv=new WebView(context);
      StringBuilder sb=new StringBuilder(wv.getSettings().getUserAgentString());
      sb.append("String_Node_Str");
      sb.append(userAgentAdd);
      this.userAgent=sb.toString();
      this.publicKey=optString(general,"String_Node_Str");
    }
    JSONObject navigation=this.json.optJSONObject("String_Node_Str");
    if (navigation != null) {
      int numActiveMenus=0;
      JSONObject sidebarNav=navigation.optJSONObject("String_Node_Str");
      if (sidebarNav != null) {
        JSONArray menus=sidebarNav.optJSONArray("String_Node_Str");
        if (menus != null) {
          for (int i=0; i < menus.length(); i++) {
            JSONObject menu=menus.optJSONObject(i);
            if (menu != null) {
              if (!menu.optBoolean("String_Node_Str",false)) {
                continue;
              }
              numActiveMenus++;
              String name=optString(menu,"String_Node_Str");
              JSONArray items=menu.optJSONArray("String_Node_Str");
              if (name != null && items != null) {
                this.menus.put(name,items);
                if (name.equals("String_Node_Str")) {
                  this.showNavigationMenu=true;
                }
              }
            }
          }
        }
        this.userIdRegex=optString(sidebarNav,"String_Node_Str");
        JSONObject menuSelectionConfig=sidebarNav.optJSONObject("String_Node_Str");
        if (numActiveMenus > 1 && menuSelectionConfig != null) {
          this.loginDetectionUrl=optString(menuSelectionConfig,"String_Node_Str");
          JSONArray redirectLocations=menuSelectionConfig.optJSONArray("String_Node_Str");
          if (redirectLocations != null) {
            for (int i=0; i < redirectLocations.length(); i++) {
              JSONObject entry=redirectLocations.optJSONObject(i);
              if (entry != null) {
                String regex=optString(entry,"String_Node_Str");
                if (regex != null) {
                  this.loginDetectRegexes.add(Pattern.compile(regex));
                  this.loginDetectLocations.add(entry);
                }
              }
            }
          }
        }
      }
      JSONObject navigationLevels=navigation.optJSONObject("String_Node_Str");
      if (navigationLevels != null && navigationLevels.optBoolean("String_Node_Str",false)) {
        JSONArray urlLevels=navigationLevels.optJSONArray("String_Node_Str");
        if (urlLevels != null) {
          for (int i=0; i < urlLevels.length(); i++) {
            JSONObject entry=urlLevels.optJSONObject(i);
            if (entry != null) {
              String regex=optString(entry,"String_Node_Str");
              int level=entry.optInt("String_Node_Str",-1);
              if (regex != null && level != -1) {
                this.navStructureLevelsRegex.add(Pattern.compile(regex));
                this.navStructureLevels.add(level);
              }
            }
          }
        }
      }
      JSONObject navigationTitles=navigation.optJSONObject("String_Node_Str");
      if (navigationTitles != null && navigationTitles.optBoolean("String_Node_Str",false)) {
        JSONArray titles=navigationTitles.optJSONArray("String_Node_Str");
        if (titles != null) {
          for (int i=0; i < titles.length(); i++) {
            JSONObject entry=titles.optJSONObject(i);
            if (entry != null) {
              String regex=optString(entry,"String_Node_Str");
              if (regex != null) {
                try {
                  HashMap<String,Object> toAdd=new HashMap<String,Object>();
                  Pattern pattern=Pattern.compile(entry.getString("String_Node_Str"));
                  toAdd.put("String_Node_Str",pattern);
                  String title=optString(entry,"String_Node_Str");
                  String urlRegex=optString(entry,"String_Node_Str");
                  int urlChompWords=entry.optInt("String_Node_Str",-1);
                  if (title != null) {
                    toAdd.put("String_Node_Str",title);
                  }
                  if (urlRegex != null) {
                    Pattern urlRegexPattern=Pattern.compile(urlRegex);
                    toAdd.put("String_Node_Str",urlRegexPattern);
                  }
                  if (urlChompWords != -1) {
                    toAdd.put("String_Node_Str",urlChompWords);
                  }
                  this.navTitles.add(toAdd);
                }
 catch (                PatternSyntaxException e) {
                  Log.e(TAG,e.getMessage(),e);
                }
              }
            }
          }
        }
      }
      this.profilePickerJS=optString(navigation,"String_Node_Str");
      JSONObject regexInternalExternal=navigation.optJSONObject("String_Node_Str");
      if (regexInternalExternal != null) {
        JSONArray rules=regexInternalExternal.optJSONArray("String_Node_Str");
        if (rules != null) {
          for (int i=0; i < rules.length(); i++) {
            JSONObject entry=rules.optJSONObject(i);
            if (entry != null && entry.has("String_Node_Str") && entry.has("String_Node_Str")) {
              String regex=optString(entry,"String_Node_Str");
              boolean internal=entry.optBoolean("String_Node_Str",true);
              if (regex != null) {
                this.regexInternalExternal.add(Pattern.compile(regex));
                this.regexIsInternal.add(internal);
              }
            }
          }
        }
      }
    }
    JSONObject styling=this.json.optJSONObject("String_Node_Str");
    this.customCss=optString(styling,"String_Node_Str");
    this.forceViewportWidth=styling.optDouble("String_Node_Str",Double.NaN);
    this.interceptHtml=this.customCss != null || !Double.isNaN(this.forceViewportWidth);
    this.showActionBar=styling.optBoolean("String_Node_Str",true);
    this.androidTheme=optString(styling,"String_Node_Str");
    this.interactiveDelay=styling.optDouble("String_Node_Str",Double.NaN);
    JSONObject forms=this.json.optJSONObject("String_Node_Str");
    if (forms != null) {
      JSONObject search=forms.optJSONObject("String_Node_Str");
      if (search != null && search.optBoolean("String_Node_Str",false)) {
        this.searchTemplateUrl=optString(search,"String_Node_Str");
      }
      JSONObject loginConfig=forms.optJSONObject("String_Node_Str");
      if (loginConfig != null && loginConfig.optBoolean("String_Node_Str",false)) {
        this.loginConfig=loginConfig;
        this.loginUrl=optString(loginConfig,"String_Node_Str");
        this.loginIsFirstPage=loginConfig.optBoolean("String_Node_Str",false);
      }
      JSONObject signupConfig=forms.optJSONObject("String_Node_Str");
      if (signupConfig != null && signupConfig.optBoolean("String_Node_Str",false)) {
        this.signupConfig=signupConfig;
        this.signupUrl=optString(signupConfig,"String_Node_Str");
      }
    }
    JSONObject permissions=this.json.optJSONObject("String_Node_Str");
    if (permissions != null) {
      this.usesGeolocation=permissions.optBoolean("String_Node_Str",false);
    }
    this.allowZoom=this.json.optBoolean("String_Node_Str",true);
  }
 catch (  Exception e) {
    Log.e(TAG,e.getMessage(),e);
  }
 finally {
    IOUtils.close(is);
    IOUtils.close(jsonIs);
  }
}

Fixed version (ground truth):
private AppConfig(Context context){
  this.context=context;
  InputStream is=null;
  InputStream jsonIs=null;
  try {
    if (fileForOTAconfig().exists()) {
      InputStream otaIS=null;
      try {
        otaIS=new BufferedInputStream(new FileInputStream(fileForOTAconfig()));
        ByteArrayOutputStream baos=new ByteArrayOutputStream();
        IOUtils.copy(otaIS,baos);
        baos.close();
        this.json=new JSONObject(baos.toString("String_Node_Str"));
      }
 catch (      Exception e) {
        Log.e(TAG,e.getMessage(),e);
        IOUtils.close(otaIS);
      }
    }
    if (this.json == null) {
      jsonIs=context.getAssets().open("String_Node_Str");
      ByteArrayOutputStream baos=new ByteArrayOutputStream();
      IOUtils.copy(jsonIs,baos);
      IOUtils.close(baos);
      this.json=new JSONObject(baos.toString("String_Node_Str"));
    }
    this.menus=new HashMap<String,JSONArray>();
    this.loginDetectRegexes=new ArrayList<Pattern>();
    this.loginDetectLocations=new ArrayList<JSONObject>();
    this.navStructureLevelsRegex=new ArrayList<Pattern>();
    this.navStructureLevels=new ArrayList<Integer>();
    this.navTitles=new ArrayList<HashMap<String,Object>>();
    this.regexInternalExternal=new ArrayList<Pattern>();
    this.regexIsInternal=new ArrayList<Boolean>();
    JSONObject general=this.json.optJSONObject("String_Node_Str");
    if (general != null) {
      this.initialUrl=optString(general,"String_Node_Str");
      initialHost=Uri.parse(this.initialUrl).getHost();
      if (initialHost.startsWith("String_Node_Str")) {
        initialHost=initialHost.substring("String_Node_Str".length());
      }
      this.appName=optString(general,"String_Node_Str");
      String userAgentAdd=optString(general,"String_Node_Str");
      if (userAgentAdd == null)       userAgentAdd="String_Node_Str";
      WebView wv=new WebView(context);
      StringBuilder sb=new StringBuilder(wv.getSettings().getUserAgentString());
      sb.append("String_Node_Str");
      sb.append(userAgentAdd);
      this.userAgent=sb.toString();
      this.publicKey=optString(general,"String_Node_Str");
    }
    JSONObject forms=this.json.optJSONObject("String_Node_Str");
    if (forms != null) {
      JSONObject search=forms.optJSONObject("String_Node_Str");
      if (search != null && search.optBoolean("String_Node_Str",false)) {
        this.searchTemplateUrl=optString(search,"String_Node_Str");
      }
      JSONObject loginConfig=forms.optJSONObject("String_Node_Str");
      if (loginConfig != null && loginConfig.optBoolean("String_Node_Str",false)) {
        this.loginConfig=loginConfig;
        this.loginUrl=optString(loginConfig,"String_Node_Str");
        this.loginIsFirstPage=loginConfig.optBoolean("String_Node_Str",false);
      }
      JSONObject signupConfig=forms.optJSONObject("String_Node_Str");
      if (signupConfig != null && signupConfig.optBoolean("String_Node_Str",false)) {
        this.signupConfig=signupConfig;
        this.signupUrl=optString(signupConfig,"String_Node_Str");
      }
    }
    JSONObject navigation=this.json.optJSONObject("String_Node_Str");
    if (navigation != null) {
      int numActiveMenus=0;
      JSONObject sidebarNav=navigation.optJSONObject("String_Node_Str");
      if (sidebarNav != null) {
        JSONArray menus=sidebarNav.optJSONArray("String_Node_Str");
        if (menus != null) {
          for (int i=0; i < menus.length(); i++) {
            JSONObject menu=menus.optJSONObject(i);
            if (menu != null) {
              if (!menu.optBoolean("String_Node_Str",false)) {
                continue;
              }
              numActiveMenus++;
              String name=optString(menu,"String_Node_Str");
              JSONArray items=menu.optJSONArray("String_Node_Str");
              if (name != null && items != null) {
                this.menus.put(name,items);
                if (name.equals("String_Node_Str")) {
                  this.showNavigationMenu=true;
                }
              }
            }
          }
        }
        this.userIdRegex=optString(sidebarNav,"String_Node_Str");
        JSONObject menuSelectionConfig=sidebarNav.optJSONObject("String_Node_Str");
        if ((numActiveMenus > 1 || this.loginIsFirstPage) && menuSelectionConfig != null) {
          this.loginDetectionUrl=optString(menuSelectionConfig,"String_Node_Str");
          JSONArray redirectLocations=menuSelectionConfig.optJSONArray("String_Node_Str");
          if (redirectLocations != null) {
            for (int i=0; i < redirectLocations.length(); i++) {
              JSONObject entry=redirectLocations.optJSONObject(i);
              if (entry != null) {
                String regex=optString(entry,"String_Node_Str");
                if (regex != null) {
                  this.loginDetectRegexes.add(Pattern.compile(regex));
                  this.loginDetectLocations.add(entry);
                }
              }
            }
          }
        }
      }
      JSONObject navigationLevels=navigation.optJSONObject("String_Node_Str");
      if (navigationLevels != null && navigationLevels.optBoolean("String_Node_Str",false)) {
        JSONArray urlLevels=navigationLevels.optJSONArray("String_Node_Str");
        if (urlLevels != null) {
          for (int i=0; i < urlLevels.length(); i++) {
            JSONObject entry=urlLevels.optJSONObject(i);
            if (entry != null) {
              String regex=optString(entry,"String_Node_Str");
              int level=entry.optInt("String_Node_Str",-1);
              if (regex != null && level != -1) {
                this.navStructureLevelsRegex.add(Pattern.compile(regex));
                this.navStructureLevels.add(level);
              }
            }
          }
        }
      }
      JSONObject navigationTitles=navigation.optJSONObject("String_Node_Str");
      if (navigationTitles != null && navigationTitles.optBoolean("String_Node_Str",false)) {
        JSONArray titles=navigationTitles.optJSONArray("String_Node_Str");
        if (titles != null) {
          for (int i=0; i < titles.length(); i++) {
            JSONObject entry=titles.optJSONObject(i);
            if (entry != null) {
              String regex=optString(entry,"String_Node_Str");
              if (regex != null) {
                try {
                  HashMap<String,Object> toAdd=new HashMap<String,Object>();
                  Pattern pattern=Pattern.compile(entry.getString("String_Node_Str"));
                  toAdd.put("String_Node_Str",pattern);
                  String title=optString(entry,"String_Node_Str");
                  String urlRegex=optString(entry,"String_Node_Str");
                  int urlChompWords=entry.optInt("String_Node_Str",-1);
                  if (title != null) {
                    toAdd.put("String_Node_Str",title);
                  }
                  if (urlRegex != null) {
                    Pattern urlRegexPattern=Pattern.compile(urlRegex);
                    toAdd.put("String_Node_Str",urlRegexPattern);
                  }
                  if (urlChompWords != -1) {
                    toAdd.put("String_Node_Str",urlChompWords);
                  }
                  this.navTitles.add(toAdd);
                }
 catch (                PatternSyntaxException e) {
                  Log.e(TAG,e.getMessage(),e);
                }
              }
            }
          }
        }
      }
      this.profilePickerJS=optString(navigation,"String_Node_Str");
      JSONObject regexInternalExternal=navigation.optJSONObject("String_Node_Str");
      if (regexInternalExternal != null) {
        JSONArray rules=regexInternalExternal.optJSONArray("String_Node_Str");
        if (rules != null) {
          for (int i=0; i < rules.length(); i++) {
            JSONObject entry=rules.optJSONObject(i);
            if (entry != null && entry.has("String_Node_Str") && entry.has("String_Node_Str")) {
              String regex=optString(entry,"String_Node_Str");
              boolean internal=entry.optBoolean("String_Node_Str",true);
              if (regex != null) {
                this.regexInternalExternal.add(Pattern.compile(regex));
                this.regexIsInternal.add(internal);
              }
            }
          }
        }
      }
    }
    JSONObject styling=this.json.optJSONObject("String_Node_Str");
    this.customCss=optString(styling,"String_Node_Str");
    this.forceViewportWidth=styling.optDouble("String_Node_Str",Double.NaN);
    this.interceptHtml=this.customCss != null || !Double.isNaN(this.forceViewportWidth);
    this.showActionBar=styling.optBoolean("String_Node_Str",true);
    this.androidTheme=optString(styling,"String_Node_Str");
    this.interactiveDelay=styling.optDouble("String_Node_Str",Double.NaN);
    JSONObject permissions=this.json.optJSONObject("String_Node_Str");
    if (permissions != null) {
      this.usesGeolocation=permissions.optBoolean("String_Node_Str",false);
    }
    this.allowZoom=this.json.optBoolean("String_Node_Str",true);
  }
 catch (  Exception e) {
    Log.e(TAG,e.getMessage(),e);
  }
 finally {
    IOUtils.close(is);
    IOUtils.close(jsonIs);
  }
}