This wouldn't happen on Jenkins 1.498:

      Exception: java.lang.NullPointerException
      Stacktrace:
      javax.servlet.ServletException: java.lang.NullPointerException
      	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:615)
      	at org.kohsuke.stapler.Stapler.invoke(Stapler.java:658)
      	at org.kohsuke.stapler.MetaClass$6.doDispatch(MetaClass.java:241)
      	...
      Caused by: java.lang.NullPointerException
      	at java.util.Vector.addAll(Unknown Source)
      	at hudson.model.AbstractProject.getActions(AbstractProject.java:1110)
      	at hudson.model.Actionable.getActions(Actionable.java:88)
      	at hudson.plugins.jobConfigHistory.JobConfigHistoryActionFactory.createFor(JobConfigHistoryActionFactory.java:30)
      	at hudson.model.AbstractProject.createTransientActions(AbstractProject.java:698)
      	at hudson.maven.AbstractMavenProject.createTransientActions(AbstractMavenProject.java:177)
      	at hudson.maven.MavenModuleSet.createTransientActions(MavenModuleSet.java:448)
      	at hudson.model.AbstractProject.updateTransientActions(AbstractProject.java:688)
      	at hudson.maven.MavenModuleSet.updateTransientActions(MavenModuleSet.java:444)
      	at hudson.model.AbstractProject.save(AbstractProject.java:266)
      	at hudson.model.Job.onLoad(Job.java:192)
      	at hudson.model.AbstractProject.onLoad(AbstractProject.java:278)
      	at hudson.maven.MavenModuleSet.onLoad(MavenModuleSet.java:746)
      	at hudson.model.Items.load(Items.java:221)
      	at hudson.model.ItemGroupMixIn.copy(ItemGroupMixIn.java:208)
      	at hudson.model.ItemGroupMixIn.createTopLevelItem(ItemGroupMixIn.java:164)
      	at jenkins.model.Jenkins.doCreateItem(Jenkins.java:2857)
      	at jenkins.model.Jenkins.doCreateItem(Jenkins.java:308)
      	at hudson.model.ListView.doCreateItem(ListView.java:208)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      	at java.lang.reflect.Method.invoke(Unknown Source)
      	at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:288)
      	at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:151)
      	at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:90)
      	at org.kohsuke.stapler.MetaClass$1.doDispatch(MetaClass.java:111)
      	at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:53)
      	at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:573)
      	... 62 more
      

          [JENKINS-16499] NPE when new job by copy from existing one

          Pei-Tang Huang created issue -
          Pei-Tang Huang made changes -
          Summary Original: When copying job configuration, Jenkins throws NullPointerException New: NPE new job by copy existing job
          Pei-Tang Huang made changes -
          Summary Original: NPE new job by copy existing job New: NPE when new job by copy from existing one

          This problem happens on a clean 1.500 install too, steps to produce:

          1. Start the clean Jenkins installation
          2. New maven project, named "test", OK and then OK
          3. New job named "npe", select copy existing Job from "test"

          Pei-Tang Huang added a comment - This problem happens on a clean 1.500 install too, steps to produce: Start the clean Jenkins installation New maven project, named "test", OK and then OK New job named "npe", select copy existing Job from "test"

          Which version of the jobconfighistory plugin do you use in your jenkins?

          Stefan Brausch added a comment - Which version of the jobconfighistory plugin do you use in your jenkins?

          Dirk Kuypers added a comment -

          I have the same issue since upgrading to 1.500 and I am using version 2.1.1 of the jobconfighistory plugin.

          Dirk Kuypers added a comment - I have the same issue since upgrading to 1.500 and I am using version 2.1.1 of the jobconfighistory plugin.

          @stefanbrausch: I think the version of JobConfigHistory is irrelevant. You can try the steps in the first comment to test if you can reproduce this problem without any plugins installed.

          Pei-Tang Huang added a comment - @stefanbrausch: I think the version of JobConfigHistory is irrelevant. You can try the steps in the first comment to test if you can reproduce this problem without any plugins installed.

          I can confirm this.

          We have a lot of complicated and quite similar jobs, so we always create new jobs based on old jobs making this issue critical to us. Please let me know if anybody finds a temporary workaround.

          Thanks!

          David Langeland added a comment - I can confirm this. We have a lot of complicated and quite similar jobs, so we always create new jobs based on old jobs making this issue critical to us. Please let me know if anybody finds a temporary workaround. Thanks!

          epikur2412 added a comment -

          I tried to upload three jobs via https. The result was a return code 500 for the first job.
          Then I retried the upload for the same jobs. Now, the first job was uploaded without an error, but the second job returns an error code 500.
          And so on.

          epikur2412 added a comment - I tried to upload three jobs via https. The result was a return code 500 for the first job. Then I retried the upload for the same jobs. Now, the first job was uploaded without an error, but the second job returns an error code 500. And so on.

          Yordan Boev added a comment - - edited

          The NPE is a result of AbstractProject.getActions() calling the java.unil.Vector.addAll() method with a null parameter.
          It comes from a method implemented in the Jenkins Core:

              public synchronized List<Action> getActions() {
                  // add all the transient actions, too
                  List<Action> actions = new Vector<Action>(super.getActions());
           NPE => actions.addAll(transientActions); 
                  // return the read only list to cause a failure on plugins who try to add an action here
                  return Collections.unmodifiableList(actions);
              }
              

          maybe there should be a check if transientActions is not null.

          The problem also exists in other plugins using the Abstractproject.getActions() method in their ActionFactory classes, for example JobConfighistory and JSWidgets.
          We could catch the exception and treat it as if there were no actions for the current project (see code below). That would solve the problem, but maybe it would be better if the method getAction() in AbstractProject is changed to return null or and empty list if there are no actions for a certain project.

          Workaround:
          Old code of JobConfigHistoryActionFactory.createFor(AbstractProject project)(with NPE)

              public Collection<? extends Action> createFor(@SuppressWarnings("unchecked") AbstractProject target) {
                  final ArrayList<Action> actions = new ArrayList<Action>();
                  final List<JobConfigHistoryProjectAction> historyJobActions = target.getActions(JobConfigHistoryProjectAction.class);
                  LOG.fine(target + " already had " + historyJobActions);
                  final JobConfigHistoryProjectAction newAction = new JobConfigHistoryProjectAction(target);
                  actions.add(newAction);
                  LOG.fine(this + " adds " + newAction + " for " + target);
                  return actions;
              }
          

          New code of JobConfigHistoryActionFactory.createFor(AbstractProject project)(catching the NPE)

              public Collection<? extends Action> createFor(@SuppressWarnings("rawtypes") AbstractProject target) {
                  List<JobConfigHistoryProjectAction> historyJobActions;
                  try {
                      historyJobActions = target.getActions(JobConfigHistoryProjectAction.class);
                  } catch (NullPointerException e) {
                      historyJobActions = null;
                  }
          
                  if (historyJobActions != null && !historyJobActions.isEmpty()) {
                      return historyJobActions;
                  }
                  final ArrayList<Action> actions = new ArrayList<Action>();
                  final JobConfigHistoryProjectAction newAction = new JobConfigHistoryProjectAction(target);
                  actions.add(newAction);
                  return actions;
              }
          

          Yordan Boev added a comment - - edited The NPE is a result of AbstractProject.getActions() calling the java.unil.Vector.addAll() method with a null parameter. It comes from a method implemented in the Jenkins Core: public synchronized List<Action> getActions() { // add all the transient actions, too List<Action> actions = new Vector<Action>( super .getActions()); NPE => actions.addAll(transientActions); // return the read only list to cause a failure on plugins who try to add an action here return Collections.unmodifiableList(actions); } maybe there should be a check if transientActions is not null. The problem also exists in other plugins using the Abstractproject.getActions() method in their ActionFactory classes, for example JobConfighistory and JSWidgets. We could catch the exception and treat it as if there were no actions for the current project (see code below). That would solve the problem, but maybe it would be better if the method getAction() in AbstractProject is changed to return null or and empty list if there are no actions for a certain project. Workaround: Old code of JobConfigHistoryActionFactory.createFor(AbstractProject project)(with NPE) public Collection<? extends Action> createFor(@SuppressWarnings( "unchecked" ) AbstractProject target) { final ArrayList<Action> actions = new ArrayList<Action>(); final List<JobConfigHistoryProjectAction> historyJobActions = target.getActions(JobConfigHistoryProjectAction.class); LOG.fine(target + " already had " + historyJobActions); final JobConfigHistoryProjectAction newAction = new JobConfigHistoryProjectAction(target); actions.add(newAction); LOG.fine( this + " adds " + newAction + " for " + target); return actions; } New code of JobConfigHistoryActionFactory.createFor(AbstractProject project)(catching the NPE) public Collection<? extends Action> createFor(@SuppressWarnings( "rawtypes" ) AbstractProject target) { List<JobConfigHistoryProjectAction> historyJobActions; try { historyJobActions = target.getActions(JobConfigHistoryProjectAction.class); } catch (NullPointerException e) { historyJobActions = null ; } if (historyJobActions != null && !historyJobActions.isEmpty()) { return historyJobActions; } final ArrayList<Action> actions = new ArrayList<Action>(); final JobConfigHistoryProjectAction newAction = new JobConfigHistoryProjectAction(target); actions.add(newAction); return actions; }

            kohsuke Kohsuke Kawaguchi
            tang Pei-Tang Huang
            Votes:
            17 Vote for this issue
            Watchers:
            37 Start watching this issue

              Created:
              Updated:
              Resolved: