You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Paul Benedict (JIRA)" <ji...@apache.org> on 2007/08/21 10:43:34 UTC

[jira] Updated: (STR-2310) NPE in ModuleUtils.selectModule

     [ https://issues.apache.org/struts/browse/STR-2310?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul Benedict updated STR-2310:
-------------------------------

    Affects Version/s: 1.2.2
                       1.2.4
                       1.2.6 Beta
        Fix Version/s: 1.2.7
             Assignee:     (was: Struts Developers)

> NPE in ModuleUtils.selectModule
> -------------------------------
>
>                 Key: STR-2310
>                 URL: https://issues.apache.org/struts/browse/STR-2310
>             Project: Struts 1
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.2.2, 1.2.4, 1.2.6 Beta, Nightly Build
>         Environment: Operating System: Windows XP
> Platform: PC
>            Reporter: Rich Feit
>            Priority: Minor
>             Fix For: 1.2.7, 1.2 Family
>
>
> If you pass in an unresolvable module prefix to ModuleUtils.selectModule(), you
> get an NPE when the method tries to find message resources for the (null)
> module.  It looks like the method is meant to handle unresolvable modules,
> though, since it initially does a null check after calling getModuleConfig().
> Made this P3 because it's easy to work around.  To reproduce this, just call
> ModuleUtils.getInstance().selectModule( "/xyzzy", request, context ); where
> "/xyzzy" is not a registered module.
> Here's a patch (as if you need it :)):
> Index: src/share/org/apache/struts/util/ModuleUtils.java
> ===================================================================
> --- src/share/org/apache/struts/util/ModuleUtils.java   (revision 111678)
> +++ src/share/org/apache/struts/util/ModuleUtils.java   (working copy)
> @@ -241,20 +241,20 @@
>          if (config != null) {
>              request.setAttribute(Globals.MODULE_KEY, config);
> +
> +            MessageResourcesConfig[] mrConfig =
> config.findMessageResourcesConfigs();
> +            for(int i = 0; i < mrConfig.length; i++) {
> +              String key = mrConfig[i].getKey();
> +              MessageResources resources =
> +                (MessageResources) context.getAttribute(key + prefix);
> +              if (resources != null) {
> +                  request.setAttribute(key, resources);
> +              } else {
> +                  request.removeAttribute(key);
> +              }
> +            }
>          } else {
>              request.removeAttribute(Globals.MODULE_KEY);
>          }
> -
> -        MessageResourcesConfig[] mrConfig = config.findMessageResourcesConfigs();
> -        for(int i = 0; i < mrConfig.length; i++) {
> -          String key = mrConfig[i].getKey();
> -          MessageResources resources =
> -            (MessageResources) context.getAttribute(key + prefix);
> -          if (resources != null) {
> -              request.setAttribute(key, resources);
> -          } else {
> -              request.removeAttribute(key);
> -          }
> -        }
>      }
>  }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.