Uploaded image for project: 'Struts 1'
  1. Struts 1
  2. STR-2310

NPE in ModuleUtils.selectModule

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.2.2, 1.2.4, 1.2.6 Beta, Nightly Build
    • 1.2.7, 1.2 Family
    • Core
    • None
    • Operating System: Windows XP
      Platform: PC
    • 32661

    Description

      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); - }
      • }
        }
        }

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              rich@apache.org Rich Feit
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: