Yordan Boev edited a comment on Bug JENKINS-16499

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;
    }
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira

--
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply via email to