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

BuildStepCompatibilityLayer.perform throws UnsupportedOperation when invoked using classes that subclass Build

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • core

      The following code will throw an unsupported operation.

      FreeStyleBuild mock = Mockito.mock(FreeStyleBuild.class,Mockito.CALLS_REAL_METHODS);		
      ArtifactArchiver artifactArchiver = new ArtifactArchiver("", "", true);
      artifactArchiver.perform(mock, null, null);
      

      I came across the issue when trying to call the ArtifactArchiver via the groovy plugin on a MatrixRun build.

      The BuildStepCompatibilityLayer should check if the implementing BuildStep provides an implementation of the perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener)

          [JENKINS-18734] BuildStepCompatibilityLayer.perform throws UnsupportedOperation when invoked using classes that subclass Build

          Brendan Nolan added a comment -

          Brendan Nolan added a comment - Added pull request - https://github.com/jenkinsci/jenkins/pull/847

          kutzi added a comment -

          What's the real world (i.e. apart from unit testing) problem, you're trying to fix here?
          AFAIK perform(Build<?,?> build, ...) is throwing UnsupportedOperationException for a good reason: because it shouldn't be usead anymore.

          kutzi added a comment - What's the real world (i.e. apart from unit testing) problem, you're trying to fix here? AFAIK perform(Build<?,?> build, ...) is throwing UnsupportedOperationException for a good reason: because it shouldn't be usead anymore.

          Brendan Nolan added a comment -

          Since the FreeStyleBuild and MatrixRun still subclass Build the perform(Build<?,?> build, ...) in BuildStepCompatabilityLayer will be if called if you using Reflection.

          As I said I encountered the issue when trying to invoke the ArtifactArchiver using the groovy plugin which internally looks to use Reflection to invoke the call.

          So we have a situation that it would work when called from a Maven build but not a FreeStyleBuild or MatrixRun build. Maybe the proper fix is to change the class hierarchy of FreeStyleBuild and MatrixRun.

          Brendan Nolan added a comment - Since the FreeStyleBuild and MatrixRun still subclass Build the perform(Build<?,?> build, ...) in BuildStepCompatabilityLayer will be if called if you using Reflection. As I said I encountered the issue when trying to invoke the ArtifactArchiver using the groovy plugin which internally looks to use Reflection to invoke the call. So we have a situation that it would work when called from a Maven build but not a FreeStyleBuild or MatrixRun build. Maybe the proper fix is to change the class hierarchy of FreeStyleBuild and MatrixRun.

          kutzi added a comment -

          I see.

          See pull request for additional remarks.

          kutzi added a comment - I see. See pull request for additional remarks.

          Brendan Nolan added a comment -

          Replied on pull request to comments.

          I think the StackOverflowError is preferable to the UnsupportedOperationException which is clearly wrong. But if you don't like the fix I'll resolve as won't fix.

          Brendan Nolan added a comment - Replied on pull request to comments. I think the StackOverflowError is preferable to the UnsupportedOperationException which is clearly wrong. But if you don't like the fix I'll resolve as won't fix.

          Oleg Nenashev added a comment -

          The PR has not been merged yet...

          Oleg Nenashev added a comment - The PR has not been merged yet...

          Code changed in jenkins
          User: Brendan Nolan
          Path:
          core/src/main/java/hudson/tasks/BuildStepCompatibilityLayer.java
          core/src/test/java/hudson/tasks/BuildStepCompatibilityLayerTest.java
          http://jenkins-ci.org/commit/jenkins/01fe717f35f60aa92f13e1117e489b3d297e3e70
          Log:
          JENKINS-18734 - Call perform(AbstractBuild build, Launcher launcher, BuildListener listener) if implemented in BuildStep

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Brendan Nolan Path: core/src/main/java/hudson/tasks/BuildStepCompatibilityLayer.java core/src/test/java/hudson/tasks/BuildStepCompatibilityLayerTest.java http://jenkins-ci.org/commit/jenkins/01fe717f35f60aa92f13e1117e489b3d297e3e70 Log: JENKINS-18734 - Call perform(AbstractBuild build, Launcher launcher, BuildListener listener) if implemented in BuildStep

          Code changed in jenkins
          User: Oleg Nenashev
          Path:
          core/src/main/java/hudson/tasks/BuildStepCompatibilityLayer.java
          core/src/test/java/hudson/tasks/BuildStepCompatibilityLayerTest.java
          http://jenkins-ci.org/commit/jenkins/fe4266b7d1134cd717ac73600f49f156151f9e95
          Log:
          Merge pull request #847 from bstick12/JENKINS-18734

          JENKINS-18734 - Call perform(AbstractBuild build, Launcher launcher, BuildListener listener) if implemented in BuildStep

          Compare: https://github.com/jenkinsci/jenkins/compare/37d2e6a9b3af...fe4266b7d113

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Oleg Nenashev Path: core/src/main/java/hudson/tasks/BuildStepCompatibilityLayer.java core/src/test/java/hudson/tasks/BuildStepCompatibilityLayerTest.java http://jenkins-ci.org/commit/jenkins/fe4266b7d1134cd717ac73600f49f156151f9e95 Log: Merge pull request #847 from bstick12/ JENKINS-18734 JENKINS-18734 - Call perform(AbstractBuild build, Launcher launcher, BuildListener listener) if implemented in BuildStep Compare: https://github.com/jenkinsci/jenkins/compare/37d2e6a9b3af...fe4266b7d113

          Oleg Nenashev added a comment -

          The fix has been integrated towards 2.47

          Oleg Nenashev added a comment - The fix has been integrated towards 2.47

            bstick12 Brendan Nolan
            bstick12 Brendan Nolan
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: