• Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • other
    • None
    • Platform: All, OS: Windows XP

      On Windows you get an NPE in the Configuration screen; I tracked this down to
      hudson.util.FormFieldValidator line 368, where the system attempts to retrieve
      the PATH environment variable. Unfortunately this is case sensitive, and many
      Windows installations store this variable under the value Path - so it returns
      null, resulting in the NPE.

          [JENKINS-1115] NullPointerException in Configuration Screen

          Starting 1.162, EnvVars.masterEnvVars handles case insensitive look up
          correctly, so this should no longer be an issue. I'm assuming that you've been
          using an older version of Hudson.

          That said, technically speaking it's possible that PATH/Path is not set at all,
          regardless of upper/lower convention, so I added null check too. This change
          will be in 1.165.

          Kohsuke Kawaguchi added a comment - Starting 1.162, EnvVars.masterEnvVars handles case insensitive look up correctly, so this should no longer be an issue. I'm assuming that you've been using an older version of Hudson. That said, technically speaking it's possible that PATH/Path is not set at all, regardless of upper/lower convention, so I added null check too. This change will be in 1.165.

          mahoney266 added a comment -

          Odd; the only version I have ever downloaded is 1.164, and renaming my Path
          variable (which definitely existed) to PATH fixed it. Never mind.

          mahoney266 added a comment - Odd; the only version I have ever downloaded is 1.164, and renaming my Path variable (which definitely existed) to PATH fixed it. Never mind.

          mahoney266 added a comment -

          Just wrote a quick test for it on my system, using hudson.EnvVars from
          hudson-1.164-src.zip. The following code fails at the second assert:

          assert EnvVars.masterEnvVars.get("Path").length() > 0;
          assert EnvVars.masterEnvVars.get("PATH") != null;

          The reason is that the static initialisation of masterEnvVars occurs before the
          static initialisation of CASE_INSENSITIVE_COMPARATOR, so that is null.

          mahoney266 added a comment - Just wrote a quick test for it on my system, using hudson.EnvVars from hudson-1.164-src.zip. The following code fails at the second assert: assert EnvVars.masterEnvVars.get("Path").length() > 0; assert EnvVars.masterEnvVars.get("PATH") != null; The reason is that the static initialisation of masterEnvVars occurs before the static initialisation of CASE_INSENSITIVE_COMPARATOR, so that is null.

          mahoney266 added a comment -

          Sorry, forgot to reopen.

          mahoney266 added a comment - Sorry, forgot to reopen.

          mahoney266 added a comment -

          Created an attachment (id=153)
          Unit Test Proving Problem

          mahoney266 added a comment - Created an attachment (id=153) Unit Test Proving Problem

          mahoney266 added a comment -

          Created an attachment (id=154)
          Patch that fixes issue

          mahoney266 added a comment - Created an attachment (id=154) Patch that fixes issue

          mahoney266 added a comment -

          Thought I'd do it properly and provide a test and patch... mocking static calls
          on java.lang classes is a pig! If you can be bothered to make the unit test
          work, you need jmockit (https://jmockit.dev.java.net/) and you must run your
          test with the following VM arguments:

          -javaagent:<full_path_to>/jmockit.jar
          -Xbootclasspath/a:"<full_path_to_EnvVars_class>:<full_path_to_EnvVarsTest_class>:<full_path_to>/junit.jar:<full_path_to>/jmockit.jar"

          Just to make it more fun, the path and classpath separators have to be system
          correct. On my machine it looks like this:

          -javaagent:c:\jmockit.jar -Xbootclasspath/a:"c:\Eclipse
          Workspaces\hudson\hudson-core\target\classes;c:\Eclipse
          Workspaces\hudson\hudson-core\target\test-classes;c:\Program
          Files\eclipse\plugins\org.junit_3.8.2.v200711021030\junit.jar;c:\jmockit.jar"

          mahoney266 added a comment - Thought I'd do it properly and provide a test and patch... mocking static calls on java.lang classes is a pig! If you can be bothered to make the unit test work, you need jmockit ( https://jmockit.dev.java.net/ ) and you must run your test with the following VM arguments: -javaagent:<full_path_to>/jmockit.jar -Xbootclasspath/a:"<full_path_to_EnvVars_class>:<full_path_to_EnvVarsTest_class>:<full_path_to>/junit.jar:<full_path_to>/jmockit.jar" Just to make it more fun, the path and classpath separators have to be system correct. On my machine it looks like this: -javaagent:c:\jmockit.jar -Xbootclasspath/a:"c:\Eclipse Workspaces\hudson\hudson-core\target\classes;c:\Eclipse Workspaces\hudson\hudson-core\target\test-classes;c:\Program Files\eclipse\plugins\org.junit_3.8.2.v200711021030\junit.jar;c:\jmockit.jar"

          mahoney266 added a comment -

          Just found this rather useful guide to using jmockit with Maven, that resolves a
          lot of the issues.

          mahoney266 added a comment - Just found this rather useful guide to using jmockit with Maven, that resolves a lot of the issues.

          mahoney266 added a comment -

          mahoney266 added a comment - http://www.jroller.com/xwarzee/entry/jmockit_maven2_how_to

          Thanks for your analysis of the issue, the patch, and the test case. I applied
          your change toward 1.166.

          If you'd like to be able to fix this kind of issues more quickly, I'd be happy
          to give you a commit access. Please write to me in e-mail if that's the case.

          Kohsuke Kawaguchi added a comment - Thanks for your analysis of the issue, the patch, and the test case. I applied your change toward 1.166. If you'd like to be able to fix this kind of issues more quickly, I'd be happy to give you a commit access. Please write to me in e-mail if that's the case.

            Unassigned Unassigned
            mahoney266 mahoney266
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: