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

IllegalArgumentException for ChoiceParameter on bindJSON saving job configuration

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Component/s: core
    • Labels:
      None
    • Environment:
      Jenkins 2.204.2
      fixed in 2.242
    • Similar Issues:
    • Released As:
      Jenkins 2.242

      Description

      I'm had implement a jenkins.branch.BranchProperty that list all available ParameterDefinition.

      It normally works but when I select a ChoiceParameter I got the following Exception on save:

      java.lang.IllegalArgumentException: Unable to convert to class java.lang.Object
      	at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:738)
      	at org.kohsuke.stapler.RequestImpl.bindJSON(RequestImpl.java:478)
      	at org.kohsuke.stapler.RequestImpl.injectSetters(RequestImpl.java:834)
      	at org.kohsuke.stapler.RequestImpl.instantiate(RequestImpl.java:784)
      	at org.kohsuke.stapler.RequestImpl.access$200(RequestImpl.java:83)
      	at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:678)
      Caused: java.lang.IllegalArgumentException: Failed to instantiate class hudson.model.ParameterDefinition from {"name":"SCENARIO","choices":"1\n2\n3","description":"","":"","stapler-class":"hudson.model.ChoiceParameterDefinition","$class":"hudson.model.ChoiceParameterDefinition"}
      	at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:681)
      	at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:717)
      	at org.kohsuke.stapler.RequestImpl.bindJSON(RequestImpl.java:478)
      	at org.kohsuke.stapler.RequestImpl.instantiate(RequestImpl.java:778)
      Caused: java.lang.IllegalArgumentException: Failed to convert the parameterDefinitions parameter of the constructor public com.thedigitalstack.jenkins.plugins.parametricrun.ParameterBranchProperty(java.lang.String,boolean,java.lang.String,java.util.List)
      	at org.kohsuke.stapler.RequestImpl.instantiate(RequestImpl.java:780)
      	at org.kohsuke.stapler.RequestImpl.access$200(RequestImpl.java:83)
      	at org.kohsuke.stapler.RequestImpl$TypePair.convertJSON(RequestImpl.java:678)
      Caused: java.lang.IllegalArgumentException: Failed to instantiate class jenkins.branch.BranchProperty from {"actionLabel":"Action Label","useBadge":false,"badgeTemplate":"Run with #$PARAMETER","parameterDefinitions":{"name":"SCENARIO","choices":"1\n2\n3","description":"","":"","stapler-class":"hudson.model.ChoiceParameterDefinition","$class":"hudson.model.ChoiceParameterDefinition"},"stapler-class":"com.thedigitalstack.jenkins.plugins.parametricrun.ParameterBranchProperty","$class":"com.thedigitalstack.jenkins.plugins.parametricrun.ParameterBranchProperty"}
             ...
      

      The RequestImpl instantiate a ChoiceParameterDefinition class and than using reflection lookup a setter @DataBoundSetter annotated for "choice" property. It takes the parameter type from method (in this unlikely case Object) and than use apache beanutils to convert the actual value "v1\n2\n3" (String) to Object. Since there are no converter registered for Object it fails.

        Attachments

          Issue Links

            Activity

            Hide
            nfalco Nikolas Falco added a comment - - edited

            Jesse Glick possible solutions are:

            • change the ChoiceParameterDefinition.setChoice from Object to String but seems there are a lot of point where they use different value to be interpreted in the setter method.
            • change the RequestImpl to not throw exception if the coverter loopup is for Object. Everything is Object this mean there is no needs convertion.
            Show
            nfalco Nikolas Falco added a comment - - edited Jesse Glick possible solutions are: change the ChoiceParameterDefinition.setChoice from Object to String but seems there are a lot of point where they use different value to be interpreted in the setter method. change the RequestImpl to not throw exception if the coverter loopup is for Object. Everything is Object this mean there is no needs convertion.
            Hide
            nfalco Nikolas Falco added a comment -

            The actual workaround is register a new ObjectConverter to bean utils like this:

                private static final class ObjectConverter implements Converter {
                    @Override
                    public Object convert(@SuppressWarnings("rawtypes") Class type, Object value) {
                        return value;
                    }
                }
            

            Although this has unknown impacts in the whole application.

            Show
            nfalco Nikolas Falco added a comment - The actual workaround is register a new ObjectConverter to bean utils like this: private static final class ObjectConverter implements Converter { @Override public Object convert(@SuppressWarnings( "rawtypes" ) Class type, Object value) { return value; } } Although this has unknown impacts in the whole application.
            Hide
            jglick Jesse Glick added a comment -

            Not sure offhand. Study JENKINS-26143.

            Show
            jglick Jesse Glick added a comment - Not sure offhand. Study JENKINS-26143 .
            Hide
            nfalco Nikolas Falco added a comment -

            Changes to the RequestImpl are not so wrong, you do not really need a converter to convert something to Object, agree?

            Show
            nfalco Nikolas Falco added a comment - Changes to the RequestImpl are not so wrong, you do not really need a converter to convert something to Object, agree?
            Hide
            danielbeck Daniel Beck added a comment -

            I'm surprised it took so long for my nonsense there to break :-/

            Show
            danielbeck Daniel Beck added a comment - I'm surprised it took so long for my nonsense there to break :-/
            Hide
            nfalco Nikolas Falco added a comment -
            Show
            nfalco Nikolas Falco added a comment - Than could be the time to review this PR https://github.com/stapler/stapler/pull/182#issuecomment-620219545
            Hide
            markewaite Mark Waite added a comment -

            Resolved in Jenkins 2.242

            Show
            markewaite Mark Waite added a comment - Resolved in Jenkins 2.242

              People

              Assignee:
              nfalco Nikolas Falco
              Reporter:
              nfalco Nikolas Falco
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: