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

NoStaplerConstructorException on UserMergeOptions.mergeStrategy

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • git-plugin
    • Jenkins 1.642.3, Pipeline 2.0, Git Plugin 2.4.4, Git Client Plugin 1.19.6

      Using Jenkins 1.642.3 and Pipeline 2.0, an exception is thrown when the DataBoundConstructor is missing from plugin code. The problem can be reproduced with the following line up: Jenkins 1.642.3, Pipeline 2.0, Git Plugin 2.4.4, Git Client Plugin 1.19.6.

      The problem did not exists with Pipeline 1.15 and Jenkins 1.642.1.

      To reproduce the problem, install those plugins, create a Pipeline job, and go in the snippet generator, then:

      • select the "checkout" step
      • select Git
      • Additional behaviors: Merge Before Build
      • Click "Generate Groovy"

      The stacktrace in the console should contain:

      Caused by: org.kohsuke.stapler.NoStaplerConstructorException: There's no @DataBoundConstructor on any constructor of class org.jenkinsci.plugins.gitclient.MergeCommand$Strategy
      

      And there is no groovy code generated.

          [JENKINS-34070] NoStaplerConstructorException on UserMergeOptions.mergeStrategy

          Jesse Glick added a comment -

          Not sure offhand what caused this to regress but it is clear from looking at the code in the Git plugin what is wrong; perhaps it just worked by accident before. UserMergeOptions has conflicting types for the mergeStrategy parameter: as a String in the @DataBoundConstructor, but as an Enum (MergeCommand.Strategy) in the matching getter.

          It must use a single consistent type for both. Best would be to use the enum in both (ideally taking the opportunity to switch to @DataBoundSetter for the optional parameters). fastForwardMode is already done this way, so following suit would allow DescriptorImpl.doFillMergeStrategyItems to be deleted in favor of f:enum in the config.jelly.

          Ironically, it seems to be you who added the new field with the proper usage style in JENKINS-12402, without fixing the definition of the existing field.

          As an aside, the two id attributes in the config.jelly are unnecessary and should be deleted.

          Jesse Glick added a comment - Not sure offhand what caused this to regress but it is clear from looking at the code in the Git plugin what is wrong ; perhaps it just worked by accident before. UserMergeOptions has conflicting types for the mergeStrategy parameter: as a String in the @DataBoundConstructor , but as an Enum ( MergeCommand.Strategy ) in the matching getter. It must use a single consistent type for both. Best would be to use the enum in both (ideally taking the opportunity to switch to @DataBoundSetter for the optional parameters). fastForwardMode is already done this way, so following suit would allow DescriptorImpl.doFillMergeStrategyItems to be deleted in favor of f:enum in the config.jelly . Ironically, it seems to be you who added the new field with the proper usage style in JENKINS-12402 , without fixing the definition of the existing field. As an aside, the two id attributes in the config.jelly are unnecessary and should be deleted.

          Martin d'Anjou added a comment - Posted pull request #392

          Code changed in jenkins
          User: Jesse Glick
          Path:
          plugin/src/main/java/org/jenkinsci/plugins/structs/describable/DescribableParameter.java
          http://jenkins-ci.org/commit/structs-plugin/86a10eec5ba906d4db9bf4641f6f7db1b8cafaa1
          Log:
          JENKINS-34070 More gracefully handle NoStaplerConstructorException.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: plugin/src/main/java/org/jenkinsci/plugins/structs/describable/DescribableParameter.java http://jenkins-ci.org/commit/structs-plugin/86a10eec5ba906d4db9bf4641f6f7db1b8cafaa1 Log: JENKINS-34070 More gracefully handle NoStaplerConstructorException.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          plugin/src/test/java/org/jenkinsci/plugins/structs/describable/DescribableModelTest.java
          http://jenkins-ci.org/commit/structs-plugin/c1660839f24d86ad6282672bd287329cbd6d861d
          Log:
          JENKINS-34070 Integration test.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: plugin/src/test/java/org/jenkinsci/plugins/structs/describable/DescribableModelTest.java http://jenkins-ci.org/commit/structs-plugin/c1660839f24d86ad6282672bd287329cbd6d861d Log: JENKINS-34070 Integration test.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          plugin/src/main/java/org/jenkinsci/plugins/structs/describable/DescribableParameter.java
          plugin/src/test/java/org/jenkinsci/plugins/structs/describable/DescribableModelTest.java
          http://jenkins-ci.org/commit/structs-plugin/f22060ee29b8d8c3cf122b1b968448496e7b16a2
          Log:
          Merge pull request #4 from jglick/JENKINS-34070-mismatch

          JENKINS-34070 Better handle mismatched types

          Compare: https://github.com/jenkinsci/structs-plugin/compare/29ee8d0ac5a8...f22060ee29b8

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: plugin/src/main/java/org/jenkinsci/plugins/structs/describable/DescribableParameter.java plugin/src/test/java/org/jenkinsci/plugins/structs/describable/DescribableModelTest.java http://jenkins-ci.org/commit/structs-plugin/f22060ee29b8d8c3cf122b1b968448496e7b16a2 Log: Merge pull request #4 from jglick/ JENKINS-34070 -mismatch JENKINS-34070 Better handle mismatched types Compare: https://github.com/jenkinsci/structs-plugin/compare/29ee8d0ac5a8...f22060ee29b8

          Jesse Glick added a comment -

          Offered an alternate patch.

          Jesse Glick added a comment - Offered an alternate patch.

          Code changed in jenkins
          User: Jesse Glick
          Path:
          src/main/java/hudson/plugins/git/UserMergeOptions.java
          src/main/resources/hudson/plugins/git/UserMergeOptions/config.jelly
          http://jenkins-ci.org/commit/git-plugin/624ffcef88c110149820e67356073285611edad9
          Log:
          JENKINS-34070 Fixing UserMergeOptions.mergeStrategy databinding.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: src/main/java/hudson/plugins/git/UserMergeOptions.java src/main/resources/hudson/plugins/git/UserMergeOptions/config.jelly http://jenkins-ci.org/commit/git-plugin/624ffcef88c110149820e67356073285611edad9 Log: JENKINS-34070 Fixing UserMergeOptions.mergeStrategy databinding.

          Code changed in jenkins
          User: Mark Waite
          Path:
          src/main/java/hudson/plugins/git/UserMergeOptions.java
          src/main/resources/hudson/plugins/git/UserMergeOptions/config.jelly
          http://jenkins-ci.org/commit/git-plugin/44e9eb0716165de33f277fd2552d6a4de2961bb0
          Log:
          Merge pull request #580 from jglick/UserMergeOptions.mergeStrategy-JENKINS-34070

          JENKINS-34070 Fixing UserMergeOptions.mergeStrategy databinding

          Compare: https://github.com/jenkinsci/git-plugin/compare/a81c6552af4a...44e9eb071616

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Mark Waite Path: src/main/java/hudson/plugins/git/UserMergeOptions.java src/main/resources/hudson/plugins/git/UserMergeOptions/config.jelly http://jenkins-ci.org/commit/git-plugin/44e9eb0716165de33f277fd2552d6a4de2961bb0 Log: Merge pull request #580 from jglick/UserMergeOptions.mergeStrategy- JENKINS-34070 JENKINS-34070 Fixing UserMergeOptions.mergeStrategy databinding Compare: https://github.com/jenkinsci/git-plugin/compare/a81c6552af4a...44e9eb071616

          Mark Waite added a comment -

          Included in git plugin 3.9.0 released 12 May 2018

          Mark Waite added a comment - Included in git plugin 3.9.0 released 12 May 2018

          René Scheibe added a comment - - edited

          This change breaks existing functionality when the extension was configured in a pipeline like this (lowercase mergeStrategy):

          checkout([$class: 'GitSCM', extensions: [[$class: 'PreBuildMerge', options: [mergeStrategy: 'default', ...]]]])
          
          java.lang.IllegalArgumentException: No enum constant org.jenkinsci.plugins.gitclient.MergeCommand.Strategy.default
          	at java.lang.Enum.valueOf(Unknown Source)
          	at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:404)
          	at org.jenkinsci.plugins.structs.describable.DescribableModel.injectSetters(DescribableModel.java:360)
          	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:283)
          Caused: java.lang.IllegalArgumentException: Could not instantiate {mergeStrategy=default, fastForwardMode=FF, mergeTarget=develop, mergeRemote=origin} for UserMergeOptions(mergeTarget: String, fastForwardMode?: GitPluginFastForwardMode[FF, FF_ONLY, NO_FF], mergeRemote?: String, mergeStrategy?: Strategy[DEFAULT, RESOLVE, RECURSIVE, OCTOPUS, OURS, SUBTREE, RECURSIVE_THEIRS])
          	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:286)
          	at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:402)
          	at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:340)
          	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:281)
          Caused: java.lang.IllegalArgumentException: Could not instantiate {options={fastForwardMode=FF, mergeRemote=origin, mergeStrategy=default, mergeTarget=develop}} for PreBuildMerge(options: UserMergeOptions(mergeTarget: String, fastForwardMode?: GitPluginFastForwardMode[FF, FF_ONLY, NO_FF], mergeRemote?: String, mergeStrategy?: Strategy[DEFAULT, RESOLVE, RECURSIVE, OCTOPUS, OURS, SUBTREE, RECURSIVE_THEIRS]))
          	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:286)
          	at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:402)
          	at org.jenkinsci.plugins.structs.describable.DescribableModel.coerceList(DescribableModel.java:485)
          	at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:387)
          	at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:340)
          	at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:281)
          

          I think this was an incorrect use anyway that worked by accident just for the value "default".

          René Scheibe added a comment - - edited This change breaks existing functionality when the extension was configured in a pipeline like this (lowercase mergeStrategy ): checkout([$class: 'GitSCM' , extensions: [[$class: 'PreBuildMerge' , options: [mergeStrategy: ' default ' , ...]]]]) java.lang.IllegalArgumentException: No enum constant org.jenkinsci.plugins.gitclient.MergeCommand.Strategy. default at java.lang.Enum.valueOf(Unknown Source) at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:404) at org.jenkinsci.plugins.structs.describable.DescribableModel.injectSetters(DescribableModel.java:360) at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:283) Caused: java.lang.IllegalArgumentException: Could not instantiate {mergeStrategy= default , fastForwardMode=FF, mergeTarget=develop, mergeRemote=origin} for UserMergeOptions(mergeTarget: String , fastForwardMode?: GitPluginFastForwardMode[FF, FF_ONLY, NO_FF], mergeRemote?: String , mergeStrategy?: Strategy[DEFAULT, RESOLVE, RECURSIVE, OCTOPUS, OURS, SUBTREE, RECURSIVE_THEIRS]) at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:286) at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:402) at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:340) at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:281) Caused: java.lang.IllegalArgumentException: Could not instantiate {options={fastForwardMode=FF, mergeRemote=origin, mergeStrategy= default , mergeTarget=develop}} for PreBuildMerge(options: UserMergeOptions(mergeTarget: String , fastForwardMode?: GitPluginFastForwardMode[FF, FF_ONLY, NO_FF], mergeRemote?: String , mergeStrategy?: Strategy[DEFAULT, RESOLVE, RECURSIVE, OCTOPUS, OURS, SUBTREE, RECURSIVE_THEIRS])) at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:286) at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:402) at org.jenkinsci.plugins.structs.describable.DescribableModel.coerceList(DescribableModel.java:485) at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:387) at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:340) at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:281) I think this was an incorrect use anyway that worked by accident just for the value "default".

            jglick Jesse Glick
            deepchip Martin d'Anjou
            Votes:
            5 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: