Commons Configuration
  1. Commons Configuration
  2. CONFIGURATION-135

[configuration] Invalid resource names in XMLConfiguration generate a NPE

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Nightly Builds
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      XMLConfiguration throws a NullPointerException if an invalid resource name is
      passed to its constructor, it should throw a ConfigurationException explaining
      the issue instead.

      Fix suggested by Ben Hutchison:

      private static File resourceURLToFile(String resource) {
      URL confURL = XMLConfiguration.class.getClassLoader().getResource(resource);
      if (confURL == null)

      { confURL = ClassLoader.getSystemResource(resource); }

      if (confURL == null)
      throw new IllegalArgumentException("Resource:"resource" not found
      thru context or system classloaders.");
      return new File(confURL.getFile());
      }

        Activity

        Emmanuel Bourg created issue -
        Hide
        David Eric Pugh added a comment -

        Looks like this bug was fixed by ebourg in version 1.12 of XMLConfiguration.
        Now closing.

        Show
        David Eric Pugh added a comment - Looks like this bug was fixed by ebourg in version 1.12 of XMLConfiguration. Now closing.
        Hide
        Emmanuel Bourg added a comment -

        Not yet, the IllegalArgumentException has to be replaced with a
        ConfigurationException.

        Show
        Emmanuel Bourg added a comment - Not yet, the IllegalArgumentException has to be replaced with a ConfigurationException.
        Hide
        David Eric Pugh added a comment -

        I was thinking of changing this from:
        throw new IllegalArgumentException("Resource: "
        + resource + " not found through context or "
        + "system classloaders.");

        to
        throw new ConfigurationRuntimeException(new IllegalArgumentException("Resource: "
        + resource + " not found through context or "
        + "system classloaders."));

        I actually don't really have a problem w/ tossing an IllegalArgumentException
        since we have them everywhere, and they are a runtime exceptions....

        Show
        David Eric Pugh added a comment - I was thinking of changing this from: throw new IllegalArgumentException("Resource: " + resource + " not found through context or " + "system classloaders."); to throw new ConfigurationRuntimeException(new IllegalArgumentException("Resource: " + resource + " not found through context or " + "system classloaders.")); I actually don't really have a problem w/ tossing an IllegalArgumentException since we have them everywhere, and they are a runtime exceptions....
        Hide
        Emmanuel Bourg added a comment -

        The load() method should throw a ConfigurationException, not a
        ConfigurationRuntimeException. This will be fixed with my upcoming refactoring
        anyway.

        Show
        Emmanuel Bourg added a comment - The load() method should throw a ConfigurationException, not a ConfigurationRuntimeException. This will be fixed with my upcoming refactoring anyway.
        Hide
        Emmanuel Bourg added a comment -

        Fixed, any error occuring on loading a configuration is now wrapped in a
        ConfigurationException.

        Show
        Emmanuel Bourg added a comment - Fixed, any error occuring on loading a configuration is now wrapped in a ConfigurationException.
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 31041 12341690
        Henri Yandell made changes -
        Key COM-1538 CONFIGURATION-135
        Affects Version/s Nightly Builds [ 12311648 ]
        Component/s Configuration [ 12311107 ]
        Project Commons [ 12310458 ] Commons Configuration [ 12310467 ]
        Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
        Henri Yandell made changes -
        Affects Version/s Nightly Builds [ 12311710 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Emmanuel Bourg
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development