Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-13465

Unable perform release: ClassCastException: net.sf.json.JSONNull cannot be cast to net.sf.json.JSONObject on Hudson 2.2.0

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • m2release-plugin
    • None

      Having m2release plugin installed on Hudson 2.2.0, it generates the following error when we try to perform a release (testing with dryRun)

      Apr 16, 2012 2:31:16 PM org.apache.catalina.core.StandardWrapperValve invoke
      SEVERE: Servlet.service() for servlet Stapler threw exception
      java.lang.ClassCastException: net.sf.json.JSONNull cannot be cast to net.sf.json.JSONObject
      at org.jvnet.hudson.plugins.m2release.M2ReleaseAction.doSubmit(M2ReleaseAction.java:239)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      ...

      Examining the source code, for M2ReleaseAction, it happens because there are not values in the form data for the parameter named "parameter"

      M2ReleaseAction Code:
      public void doSubmit(StaplerRequest req, StaplerResponse resp) ... {
      ...
      JSONArray a = JSONArray.fromObject(formData.get("parameter"));
      for (Object o : a) {
      JSONObject jo = (JSONObject) o;
      ...

      In order to solve this, check that we have "parameter"; or check for a possible JSONNull object:

      Possible Fix:
      JSONArray a = JSONArray.fromObject(formData.get("parameter"));
      for (Object o : a) {
      if (o instanceof JSONObject)

      { JSONObject jo = (JSONObject) o; ... }

      ...

      Note: The plugin is installed on Hudson with the workaround described in #JENKINS-12991

          [JENKINS-13465] Unable perform release: ClassCastException: net.sf.json.JSONNull cannot be cast to net.sf.json.JSONObject on Hudson 2.2.0

          Bruno Antunes created issue -
          Tan Nguyen made changes -
          Attachment New: m2release.hpi [ 22421 ]
          Larry Shatzer, Jr. made changes -
          Link New: This issue is duplicated by JENKINS-17264 [ JENKINS-17264 ]
          Kohsuke Kawaguchi made changes -
          Labels New: lts-candidate
          Jesse Glick made changes -
          Labels Original: lts-candidate
          James Nord made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]
          James Nord made changes -
          Status Original: Resolved [ 5 ] New: Closed [ 6 ]
          R. Tyler Croy made changes -
          Workflow Original: JNJira [ 143931 ] New: JNJira + In-Review [ 205796 ]
          James Nord made changes -
          Assignee Original: James Nord [ teilo ]

            Unassigned Unassigned
            bantunes Bruno Antunes
            Votes:
            55 Vote for this issue
            Watchers:
            55 Start watching this issue

              Created:
              Updated:
              Resolved: