[JIRA] (JENKINS-61438) IllegalArgumentException for ChoiceParameter on bindJSON saving job configuration

20 views
Skip to first unread message

nfalco79@hotmail.com (JIRA)

unread,
Mar 11, 2020, 12:13:04 PM3/11/20
to jenkinsc...@googlegroups.com
Nikolas Falco created an issue
 
Jenkins / Bug JENKINS-61438
IllegalArgumentException for ChoiceParameter on bindJSON saving job configuration
Issue Type: Bug Bug
Assignee: Unassigned
Attachments: image-2020-03-11-17-00-27-616.png
Components: core
Created: 2020-03-11 16:12
Environment: Jenkins 2.204.2
Priority: Minor Minor
Reporter: Nikolas Falco

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 and than using reflection lookup a setter @DataBoundSetter annotated for "choice" property. It takes the method parameter type (in case unlike case Object) and than use apache beanutil to convert the actual value "v1\n2\n3" (String) to Object. There are no converter registere for Object and it fails on RequestImpl.java

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38)
Atlassian logo

nfalco79@hotmail.com (JIRA)

unread,
Mar 11, 2020, 12:19:03 PM3/11/20
to jenkinsc...@googlegroups.com

nfalco79@hotmail.com (JIRA)

unread,
Mar 11, 2020, 12:23:02 PM3/11/20
to jenkinsc...@googlegroups.com
Nikolas Falco commented on Bug JENKINS-61438
 
Re: IllegalArgumentException for ChoiceParameter on bindJSON saving job configuration

The possible solutions are or 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. Or change the RequestImpl to not throw exception if the coverter loopup is for Object. Everything is Object this mean there is no needs convertion.

nfalco79@hotmail.com (JIRA)

unread,
Mar 11, 2020, 12:39:04 PM3/11/20
to jenkinsc...@googlegroups.com
Nikolas Falco updated an issue
Change By: Nikolas Falco
I'm had implement a jenkins.branch.BranchProperty that list all available ParameterDefinition.
!image-2020-03-11-17-00-27-616.png|thumbnail!


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

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"}
       ...
{noformat}

The RequestImpl instantiate a ChoiceParameterDefinition class and than using reflection lookup a setter {{ @DataBoundSetter }} annotated for "choice" property. It takes the method parameter type from method (in this unlikely case unlike case Object) and than use apache beanutil beanutils to convert the actual value "v1\n2\n3" (String) to Object. There Since there are no converter registere registered for Object and it fails on [RequestImpl . java|https://github.com/stapler/stapler/blob/c8c28eb749937ab239d7b7f94c2254340103f67e/core/src/main/java/org/kohsuke/stapler/RequestImpl.java#L736]

nfalco79@hotmail.com (JIRA)

unread,
Mar 11, 2020, 1:38:03 PM3/11/20
to jenkinsc...@googlegroups.com

nfalco79@hotmail.com (JIRA)

unread,
Mar 11, 2020, 1:38:03 PM3/11/20
to jenkinsc...@googlegroups.com
Nikolas Falco started work on Bug JENKINS-61438
 
Change By: Nikolas Falco
Status: Open In Progress

nfalco79@hotmail.com (JIRA)

unread,
Mar 11, 2020, 1:38:03 PM3/11/20
to jenkinsc...@googlegroups.com

nfalco79@hotmail.com (JIRA)

unread,
Mar 11, 2020, 1:40:03 PM3/11/20
to jenkinsc...@googlegroups.com
 
Re: IllegalArgumentException for ChoiceParameter on bindJSON saving job configuration

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.

nfalco79@hotmail.com (JIRA)

unread,
Mar 11, 2020, 1:41:05 PM3/11/20
to jenkinsc...@googlegroups.com
Nikolas Falco edited a comment on Bug JENKINS-61438
The [~jglick] possible solutions are or :
*
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. Or
*
change the RequestImpl to not throw exception if the coverter loopup is for Object. Everything is Object this mean there is no needs convertion.

jglick@cloudbees.com (JIRA)

unread,
Mar 11, 2020, 1:49:03 PM3/11/20
to jenkinsc...@googlegroups.com

nfalco79@hotmail.com (JIRA)

unread,
Mar 11, 2020, 1:53:02 PM3/11/20
to jenkinsc...@googlegroups.com

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

dbeck@cloudbees.com (JIRA)

unread,
Apr 27, 2020, 4:59:04 PM4/27/20
to jenkinsc...@googlegroups.com

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

nfalco79@hotmail.com (JIRA)

unread,
Apr 27, 2020, 5:53:02 PM4/27/20
to jenkinsc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages